/////////////////////////////////////////////////////////////////////////////
// Name:        AircraftDialog.cpp
// Purpose:     Manager of the Aircraft
// Author:      Matthew Gong
// Created:     07/21/2005
// Copyright:   (c) Matthew Gong
// Licence:     GPL licence
/////////////////////////////////////////////////////////////////////////////

#ifdef __GNUG__
// #pragma implementation
#endif

// For compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
#pragma hdrstop
#endif

#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif

// -*- C++ -*- generated by wxGlade 0.4cvs on Thu Jul 21 09:08:55 2005

#include <wx/wfstream.h>
#include <wx/txtstrm.h>
#include <wx/datetime.h>
#include <wx/fileconf.h>

#ifndef __WXMSW__
#include "aero_icon.xpm"
#include "fcs_icon.xpm"
#include "mass_icon.xpm"
#include "ap_icon.xpm"
#include "fileheader_icon.xpm"
#include "metrics_icon.xpm"
#include "engine_icon.xpm"
#include "gear_icon.xpm"
#include "output_icon.xpm"
#include "axis.xpm"
#include "operator_abs.xpm"
#include "operator_derivative.xpm"
#include "operator_product.xpm"
#include "operator_acos.xpm"
#include "operator_difference.xpm"
#include "operator_quotient.xpm"
#include "operator_asin.xpm"
#include "operator_func.xpm"
#include "operator_sin.xpm"
#include "operator_atan.xpm"
#include "operator_integral.xpm"
#include "operator_sum.xpm"
#include "operator_cos.xpm"
#include "operator_pow.xpm"
#include "operator_tan.xpm"
#include "property_icon.xpm"
#include "table_icon.xpm"
#include "value_icon.xpm"
#include "myclose.xpm"
#include "mynew.xpm"
#include "myopen.xpm"
#include "mysaveas.xpm"
#include "mysave.xpm"
#include "rocket_engine.xpm"
#include "piston_engine.xpm"
#include "turbine_engine.xpm"
#include "propeller.xpm"
#include "nozzle.xpm"
#include "direct.xpm"
#include "electric_engine.xpm"
#include "tank.xpm"
#include "operator_le.xpm"
#include "operator_lt.xpm"
#include "operator_gt.xpm"
#include "operator_ge.xpm"
#include "operator_eq.xpm"
#include "operator_ne.xpm"
#include "operator_and.xpm"
#include "operator_or.xpm"
#include "operator_not.xpm"
#include "operator_ifthen.xpm"

#endif

#include "AircraftDialog.h"
#include "Mass_Diag.h"
#include "doc.h"
#include "Commander.h"
#include "Property_Diag.h"
#include "LGear_Diag.h"

void mkNewFDMFile(const wxString & filename)
{ 
    wxFileOutputStream os(filename);
    if (!os.Ok())
      return ;
    wxTextOutputStream out(os,wxEOL_UNIX);
    wxString name = filename.AfterLast(wxGetApp().Delimited[0]);
    name = name.BeforeLast('.');

    out << wxT("<?xml version=\"1.0\"?>\n");
    out << wxT("<?xml-stylesheet href=\"JSBSim.xsl\" type=\"application/xml\"?>\n");

    out << wxT("<fdm_config name=\"") << name << wxT("\" version=\"2.0\" release=\"ALPHA\">\n");
    out << endl;
    out << wxT("    <fileheader>\n");
    out << wxT("        <author> anonymous </author>\n");
    out << wxT("        <filecreationdate> ") << wxDateTime::Now().FormatISODate() << wxT(" </filecreationdate>\n");
    out << wxT("        <version> 0.1 </version>\n");
    out << wxT("    </fileheader>\n");
    out << endl;
    out << wxT("    <metrics>\n");
    out << wxT("        <wingarea unit=\"M2\"> 0 </wingarea>\n");
    out << wxT("        <wingspan unit=\"M\"> 0 </wingspan>\n");
    out << wxT("        <chord unit=\"M\"> 0 </chord>\n");
    out << wxT("        <htailarea unit=\"M2\"> 0 </htailarea>\n");
    out << wxT("        <htailarm unit=\"M\"> 0 </htailarm>\n");
    out << wxT("        <vtailarea unit=\"M2\"> 0 </vtailarea>\n");
    out << wxT("        <vtailarm unit=\"M\"> 0 </vtailarm>\n");
    out << wxT("        <location name=\"AERORP\" unit=\"M\">\n");
    out << wxT("            <x> 0 </x>\n");
    out << wxT("            <y> 0 </y>\n");
    out << wxT("            <z> 0 </z>\n");
    out << wxT("        </location>\n");
    out << wxT("        <location name=\"EYEPOINT\" unit=\"M\">\n");
    out << wxT("            <x> 0 </x>\n");
    out << wxT("            <y> 0 </y>\n");
    out << wxT("            <z> 0 </z>\n");
    out << wxT("        </location>\n");
    out << wxT("        <location name=\"VRP\" unit=\"M\">\n");
    out << wxT("            <x> 0 </x>\n");
    out << wxT("            <y> 0 </y>\n");
    out << wxT("            <z> 0 </z>\n");
    out << wxT("        </location>\n");
    out << wxT("    </metrics>\n");
    out << endl;
    out << wxT("   <mass_balance>\n");
    out << wxT("       <ixx unit=\"KG*M2\"> 0 </ixx>\n");
    out << wxT("       <iyy unit=\"KG*M2\"> 0 </iyy>\n");
    out << wxT("       <izz unit=\"KG*M2\"> 0 </izz>\n");
    out << wxT("       <ixz unit=\"KG*M2\"> 0 </ixz>\n");
    out << wxT("       <iyz unit=\"KG*M2\"> 0 </iyz>\n");
    out << wxT("       <ixy unit=\"KG*M2\"> 0 </ixy>\n");
    out << wxT("       <emptywt unit=\"N\"> 0 </emptywt>\n");
    out << wxT("       <location name=\"CG\" unit=\"M\">\n");
    out << wxT("           <x> 0 </x>\n");
    out << wxT("           <y> 0 </y>\n");
    out << wxT("           <z> 0 </z>\n");
    out << wxT("       </location>\n");
    out << wxT("   </mass_balance>\n");
    out << endl;
    out << wxT("    <ground_reactions>\n");
    out << wxT("        <contact type=\"BOGEY\" name=\"NOSE_LG\">\n");
    out << wxT("            <location unit=\"M\">\n");
    out << wxT("                <x> -10 </x>\n");
    out << wxT("                <y> 0 </y>\n");
    out << wxT("                <z> -2 </z>\n");
    out << wxT("            </location>\n");
    out << wxT("            <static_friction> 0.8 </static_friction>\n");
    out << wxT("            <dynamic_friction> 0.5 </dynamic_friction>\n");
    out << wxT("            <rolling_friction> 0.02 </rolling_friction>\n");
    out << wxT("            <spring_coeff unit=\"LBS/FT\"> 15000 </spring_coeff>\n");
    out << wxT("            <damping_coeff unit=\"LBS/FT/SEC\"> 5000 </damping_coeff>\n");
    out << wxT("            <max_steer unit=\"DEG\"> 80 </max_steer>\n");
    out << wxT("            <brake_group> NOSE </brake_group>\n");
    out << wxT("            <retractable>1</retractable>\n");
    out << wxT("        </contact>\n");
    out << wxT("        <contact type=\"BOGEY\" name=\"LEFT_MLG\">\n");
    out << wxT("            <location unit=\"M\">\n");
    out << wxT("                <x> -5 </x>\n");
    out << wxT("                <y> -3 </y>\n");
    out << wxT("                <z> -2 </z>\n");
    out << wxT("            </location>\n");
    out << wxT("            <static_friction> 0.8 </static_friction>\n");
    out << wxT("            <dynamic_friction> 0.5 </dynamic_friction>\n");
    out << wxT("            <rolling_friction> 0.02 </rolling_friction>\n");
    out << wxT("            <spring_coeff unit=\"LBS/FT\"> 22704 </spring_coeff>\n");
    out << wxT("            <damping_coeff unit=\"LBS/FT/SEC\"> 10000 </damping_coeff>\n");
    out << wxT("            <max_steer unit=\"DEG\"> 0.0 </max_steer>\n");
    out << wxT("            <brake_group> LEFT </brake_group>\n");
    out << wxT("            <retractable>1</retractable>\n");
    out << wxT("        </contact>\n");
    out << wxT("        <contact type=\"BOGEY\" name=\"RIGHT_MLG\">\n");
    out << wxT("            <location unit=\"M\">\n");
    out << wxT("                <x> -5 </x>\n");
    out << wxT("                <y> 3 </y>\n");
    out << wxT("                <z> -2 </z>\n");
    out << wxT("            </location>\n");
    out << wxT("            <static_friction> 0.8 </static_friction>\n");
    out << wxT("            <dynamic_friction> 0.5 </dynamic_friction>\n");
    out << wxT("            <rolling_friction> 0.02 </rolling_friction>\n");
    out << wxT("            <spring_coeff unit=\"LBS/FT\"> 22704 </spring_coeff>\n");
    out << wxT("            <damping_coeff unit=\"LBS/FT/SEC\"> 10000 </damping_coeff>\n");
    out << wxT("            <max_steer unit=\"DEG\"> 0.0 </max_steer>\n");
    out << wxT("            <brake_group> RIGHT </brake_group>\n");
    out << wxT("            <retractable>1</retractable>\n");
    out << wxT("        </contact>\n");
    out << wxT("    </ground_reactions>\n");
    out << endl;
    out << wxT("    <propulsion>\n");
    out << wxT("        <engine file=\"F100-PW-229\">\n");
    out << wxT("            <location unit=\"M\">\n");
    out << wxT("                <x> 0.000000 </x>\n");
    out << wxT("                <y> 0.000000 </y>\n");
    out << wxT("                <z> 0.000000 </z>\n");
    out << wxT("            </location>\n");
    out << wxT("            <orient unit=\"DEG\">\n");
    out << wxT("                <roll> 0.000000 </roll>\n");
    out << wxT("                <pitch> 0.000000 </pitch>\n");
    out << wxT("                <yaw> 0.000000 </yaw>\n");
    out << wxT("            </orient>\n");
    out << wxT("            <feed>0</feed>\n");
    out << wxT("            <feed>1</feed>\n");
    out << wxT("            <thruster file=\"direct\">\n");
    out << wxT("                <location unit=\"M\">\n");
    out << wxT("                    <x> 0.000000 </x>\n");
    out << wxT("                    <y> 0.000000 </y>\n");
    out << wxT("                    <z> 0.000000 </z>\n");
    out << wxT("                </location>\n");
    out << wxT("                <orient unit=\"DEG\">\n");
    out << wxT("                    <roll> 0.000000 </roll>\n");
    out << wxT("                    <pitch> 0.000000 </pitch>\n");
    out << wxT("                    <yaw> 0.000000 </yaw>\n");
    out << wxT("                </orient>\n");
    out << wxT("            </thruster>\n");
    out << wxT("        </engine>\n");
    out << wxT("    </propulsion>\n");
    out << endl;
    out << wxT("    <flight_control name=\"fcs\">\n");
    out << endl;
    out << wxT("     <channel name=\"Pitch\">\n");
    out << endl;
    out << wxT("      <component name=\"elevator cmd limiter\" type=\"SUMMER\">\n");
    out << wxT("        <input> fcs/elevator-cmd-norm </input>\n");
    out << wxT("        <input> fcs/pitch-trim-cmd-norm </input>\n");
    out << wxT("        <clipto>\n");
    out << wxT("          <min> -1.000000 </min>\n");
    out << wxT("          <max> 1.000000 </max>\n");
    out << wxT("        </clipto>\n");
    out << wxT("      </component>\n");
    out << endl;
    out << wxT("      <component name=\"Elevator Control\" type=\"AEROSURFACE_SCALE\">\n");
    out << wxT("        <input> fcs/elevator-cmd-limiter </input>\n");
    out << wxT("        <limit>\n");
    out << wxT("          <min> -25.000 </min>\n");
    out << wxT("          <max> 25.000 </max>\n");
    out << wxT("        </limit>\n");
    out << wxT("        <output> fcs/elevator-pos-deg </output>\n");
    out << wxT("      </component>\n");
    out << endl;
    out << wxT("     </channel>\n");
    out << endl;
    out << wxT("     <channel name=\"Roll\">\n");
    out << endl;
    out << wxT("      <component name=\"roll trim error\" type=\"SUMMER\">\n");
    out << wxT("        <input> fcs/aileron-cmd-norm </input>\n");
    out << wxT("        <input> fcs/roll-trim-cmd-norm </input>\n");
    out << wxT("      </component>\n");
    out << endl;
    out << wxT("      <component name=\"Left Aileron Control\" type=\"AEROSURFACE_SCALE\">\n");
    out << wxT("        <input> -fcs/roll-trim-error </input>\n");
    out << wxT("        <limit>\n");
    out << wxT("          <min> -21.000 </min>\n");
    out << wxT("          <max> 21.000 </max>\n");
    out << wxT("        </limit>\n");
    out << wxT("        <output> fcs/left-aileron-pos-deg </output>\n");
    out << wxT("      </component>\n");
    out << endl;
    out << wxT("      <component name=\"Right Aileron Control\" type=\"AEROSURFACE_SCALE\">\n");
    out << wxT("        <input> fcs/roll-trim-error </input>\n");
    out << wxT("        <limit>\n");
    out << wxT("          <min> -21.000 </min>\n");
    out << wxT("          <max> 21.000 </max>\n");
    out << wxT("        </limit>\n");
    out << wxT("        <output> fcs/right-aileron-pos-deg </output>\n");
    out << wxT("      </component>\n");
    out << endl;
    out << wxT("     </channel>\n");
    out << endl;
    out << wxT("     <channel name=\"Yaw\">\n");
    out << endl;
    out << wxT("      <component name=\"yaw trim error\" type=\"SUMMER\">\n");
    out << wxT("        <input> fcs/rudder-cmd-norm </input>\n");
    out << wxT("        <input> fcs/yaw-trim-cmd-norm </input>\n");
    out << wxT("      </component>\n");
    out << endl;
    out << wxT("      <component name=\"Rudder Control\" type=\"AEROSURFACE_SCALE\">\n");
    out << wxT("        <input> fcs/yaw-trim-error </input>\n");
    out << wxT("        <limit>\n");
    out << wxT("          <min> -30.000 </min>\n");
    out << wxT("          <max> 30.000 </max>\n");
    out << wxT("        </limit>\n");
    out << wxT("        <output> fcs/rudder-pos-deg </output>\n");
    out << wxT("      </component>\n");
    out << endl;
    out << wxT("     </channel>\n");
    out << endl;
    out << wxT("     <channel name=\"Propulsion\">\n");
    out << endl;
    out << wxT("      <component name=\"Throttle1\" type=\"PURE_GAIN\">\n");
    out << wxT("        <input> fcs/throttle-cmd-norm </input>\n");
    out << wxT("        <gain> 2.000000 </gain>\n");
    out << wxT("        <output> fcs/throttle-pos-norm </output>\n");
    out << wxT("      </component>\n");
    out << endl;
    out << wxT("     </channel>\n");
    out << endl;
    out << wxT("     <channel name=\"Gear\">\n");
    out << endl;
    out << wxT("      <component name=\"Gear Control\" type=\"KINEMAT\">\n");
    out << wxT("        <input> gear/gear-cmd-norm </input>\n");
    out << wxT("        <traverse>\n");
    out << wxT("          <setting>\n");
    out << wxT("            <position> 0.000000 </position>\n");
    out << wxT("            <time> 0.000000 </time>\n");
    out << wxT("          </setting>\n");
    out << wxT("          <setting>\n");
    out << wxT("            <position> 1.000000 </position>\n");
    out << wxT("            <time> 5.000000 </time>\n");
    out << wxT("          </setting>\n");
    out << wxT("        </traverse>\n");
    out << wxT("        <output> gear/gear-pos-norm </output>\n");
    out << wxT("      </component>\n");
    out << endl;
    out << wxT("     </channel>\n");
    out << endl;
    out << wxT("    </flight_control>\n");
    out << endl;
    out << wxT("    <aerodynamics>\n");
    out << wxT("        <axis name=\"FORWARD\" unit=\"N\">\n");
    out << wxT("            <function name=\"aero/force/forward\">\n");
    out << wxT("                <product>\n");
    out << wxT("                    <property>aero/qbar-area-newton</property>\n");
    out << wxT("                    <sum>\n");
    out << wxT("                        <function name=\"aero/coefficient/CF1\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                        <function name=\"aero/coefficient/CF2\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                    </sum>\n");
    out << wxT("                    <value> -1.000000 </value>\n");
    out << wxT("                </product>\n");
    out << wxT("            </function>\n");
    out << wxT("        </axis>\n");
    out << wxT("        <axis name=\"RIGHT\" unit=\"N\">\n");
    out << wxT("            <function name=\"aero/force/right\">\n");
    out << wxT("                <product>\n");
    out << wxT("                    <property>aero/qbar-area-newton</property>\n");
    out << wxT("                    <sum>\n");
    out << wxT("                        <function name=\"aero/coefficient/CR1\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                        <function name=\"aero/coefficient/CR2\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                    </sum>\n");
    out << wxT("                </product>\n");
    out << wxT("            </function>\n");
    out << wxT("        </axis>\n");
    out << wxT("        <axis name=\"DOWN\" unit=\"N\">\n");
    out << wxT("            <function name=\"aero/force/down\">\n");
    out << wxT("                <product>\n");
    out << wxT("                    <property>aero/qbar-area-newton</property>\n");
    out << wxT("                    <sum>\n");
    out << wxT("                        <function name=\"aero/coefficient/CD1\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                        <function name=\"aero/coefficient/CD2\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                    </sum>\n");
    out << wxT("                    <value> -1.000000 </value>\n");
    out << wxT("                </product>\n");
    out << wxT("            </function>\n");
    out << wxT("        </axis>\n");
    out << wxT("        <axis name=\"LIFT\" unit=\"N\">\n");
    out << wxT("            <function name=\"aero/force/lift\">\n");
    out << wxT("                <product>\n");
    out << wxT("                    <property>aero/qbar-area-newton</property>\n");
    out << wxT("                    <sum>\n");
    out << wxT("                        <function name=\"aero/coefficient/CL1\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                        <function name=\"aero/coefficient/CL2\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                    </sum>\n");
    out << wxT("                </product>\n");
    out << wxT("            </function>\n");
    out << wxT("        </axis>\n");
    out << wxT("        <axis name=\"DRAG\" unit=\"N\">\n");
    out << wxT("            <function name=\"aero/force/drag\">\n");
    out << wxT("                <product>\n");
    out << wxT("                    <property>aero/qbar-area-newton</property>\n");
    out << wxT("                    <sum>\n");
    out << wxT("                        <function name=\"aero/coefficient/CD1\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                        <function name=\"aero/coefficient/CD2\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                    </sum>\n");
    out << wxT("                </product>\n");
    out << wxT("            </function>\n");
    out << wxT("        </axis>\n");
    out << wxT("        <axis name=\"SIDE\" unit=\"N\">\n");
    out << wxT("            <function name=\"aero/force/side\">\n");
    out << wxT("                <product>\n");
    out << wxT("                    <property>aero/qbar-area-newton</property>\n");
    out << wxT("                    <sum>\n");
    out << wxT("                        <function name=\"aero/coefficient/CY1\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                        <function name=\"aero/coefficient/CY2\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                    </sum>\n");
    out << wxT("                </product>\n");
    out << wxT("            </function>\n");
    out << wxT("        </axis>\n");
    out << wxT("        <axis name=\"ROLL\" unit=\"N*M\">\n");
    out << wxT("            <function name=\"aero/moment/roll\">\n");
    out << wxT("                <product>\n");
    out << wxT("                    <property>aero/qbar-area-newton</property>\n");
    out << wxT("                    <property>metrics/bw-m</property>\n");
    out << wxT("                    <sum>\n");
    out << wxT("                        <function name=\"aero/coefficient/Cl1\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                        <function name=\"aero/coefficient/Cl2\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                    </sum>\n");
    out << wxT("                </product>\n");
    out << wxT("            </function>\n");
    out << wxT("        </axis>\n");
    out << wxT("        <axis name=\"PITCH\" unit=\"N*M\">\n");
    out << wxT("            <function name=\"aero/moment/pitch\">\n");
    out << wxT("                <product>\n");
    out << wxT("                    <property>aero/qbar-area-newton</property>\n");
    out << wxT("                    <property>metrics/cbarw-m</property>\n");
    out << wxT("                    <sum>\n");
    out << wxT("                        <function name=\"aero/coefficient/Cm1\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                        <function name=\"aero/coefficient/Cm2\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                    </sum>\n");
    out << wxT("                </product>\n");
    out << wxT("            </function>\n");
    out << wxT("        </axis>\n");
    out << wxT("        <axis name=\"YAW\" unit=\"N*M\">\n");
    out << wxT("            <function name=\"aero/moment/yaw\">\n");
    out << wxT("                <product>\n");
    out << wxT("                    <property>aero/qbar-area-newton</property>\n");
    out << wxT("                    <property>metrics/bw-m</property>\n");
    out << wxT("                    <sum>\n");
    out << wxT("                        <function name=\"aero/coefficient/Cn1\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                        <function name=\"aero/coefficient/Cn2\">\n");
    out << wxT("                            <value>0.000000</value>\n");
    out << wxT("                        </function>\n");
    out << wxT("                    </sum>\n");
    out << wxT("                </product>\n");
    out << wxT("            </function>\n");
    out << wxT("        </axis>\n");
    out << wxT("    </aerodynamics>\n");
    out << wxT("    <output name=\"JSBout.csv\" type=\"CSV\" rate=\"60\">\n");
    out << wxT("        <simulation> ON </simulation>\n");
    out << wxT("        <atmosphere> OFF </atmosphere>\n");
    out << wxT("        <massprops> OFF </massprops>\n");
    out << wxT("        <aerosurfaces> ON </aerosurfaces>\n");
    out << wxT("        <rates> ON </rates>\n");
    out << wxT("        <velocities> ON </velocities>\n");
    out << wxT("        <forces> OFF </forces>\n");
    out << wxT("        <moments> OFF </moments>\n");
    out << wxT("        <position> ON </position>\n");
    out << wxT("        <coefficients> OFF </coefficients>\n");
    out << wxT("        <ground_reactions> OFF </ground_reactions>\n");
    out << wxT("        <fcs> OFF </fcs>\n");
    out << wxT("        <propulsion> OFF </propulsion>\n");
    out << wxT("    </output>\n");
    out << wxT("</fdm_config>\n");
}

AircraftDialog::AircraftDialog(wxWindow* parent, int id, const wxString& title, const wxPoint& pos, const wxSize& size, long style):
    wxDialog(parent, id, title, pos, size, style)
{
    // begin wxGlade: AircraftDialog::AircraftDialog
    frame_ac_toolbar = new wxToolBar(this, -1);
    frame_ac_toolbar->AddTool(wxID_NEW, _("New"), wxBITMAP(mynew), _("New"));
    frame_ac_toolbar->AddSeparator();
    frame_ac_toolbar->AddTool(wxID_OPEN, _("Open"), wxBITMAP(myopen), _("Open"));
    frame_ac_toolbar->AddTool(wxID_SAVE, _("Save"), wxBITMAP(mysave), _("Save"));
    frame_ac_toolbar->AddTool(wxID_SAVEAS, _("Save As"), wxBITMAP(mysaveas), _("Save As"));
    frame_ac_toolbar->AddSeparator();
    frame_ac_toolbar->AddTool(wxID_CLOSE, _("Close"), wxBITMAP(myclose), _("Close"));
    frame_ac_toolbar->Realize();
    notebook_ac = new wxNotebook(this, ID_NOTEBOOK, wxDefaultPosition, wxDefaultSize, wxNB_MULTILINE);
    notebook_ac_pane_output = new wxPanel(notebook_ac, -1);
    notebook_ac_pane_aero = new wxPanel(notebook_ac, -1);
    notebook_ac_pane_propulsion = new wxPanel(notebook_ac, -1);
    notebook_ac_pane_ground = new wxPanel(notebook_ac, -1);
    notebook_ac_pane_mass = new wxPanel(notebook_ac, -1);
    notebook_ac_pane_metrics = new wxPanel(notebook_ac, -1);
    sizer_arp_staticbox = new wxStaticBox(notebook_ac_pane_metrics, -1, _("Aerodynamic Reference Point(*)"));
    sizer_ep_staticbox = new wxStaticBox(notebook_ac_pane_metrics, -1, _("Eye Point"));
    sizer_vrp_staticbox = new wxStaticBox(notebook_ac_pane_metrics, -1, _("Visual Reference Point"));
    sizer_massloc_staticbox = new wxStaticBox(notebook_ac_pane_mass, -1, _("location(*)"));
    sizer_mass_staticbox = new wxStaticBox(notebook_ac_pane_mass, -1, _("mass"));
    sizer_moment_staticbox = new wxStaticBox(notebook_ac_pane_mass, -1, _("moment of the inertia(*)"));
    sizer_pm_staticbox = new wxStaticBox(notebook_ac_pane_mass, -1, _("Point Mass"));
    notebook_ac_pane_info = new wxPanel(notebook_ac, -1);
    label_info_name = new wxStaticText(notebook_ac_pane_info, -1, _("Aircraft Name"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_info_name = new wxTextCtrl(notebook_ac_pane_info, -1, wxT(""));
    label_info_file = new wxStaticText(notebook_ac_pane_info, -1, _("File Name"));
    text_ctrl_info_file = new wxTextCtrl(notebook_ac_pane_info, -1, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    label_info_level = new wxStaticText(notebook_ac_pane_info, -1, _("Release Level"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    const wxString combo_box_info_level_choices[] = {
        wxT("ALPHA"),
        wxT("BETA"),
        wxT("PRODUCTION")
    };
    combo_box_info_level = new wxComboBox(notebook_ac_pane_info, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 3, combo_box_info_level_choices, wxCB_DROPDOWN|wxCB_READONLY);
    label_info_cfgver = new wxStaticText(notebook_ac_pane_info, -1, _("Configuration Version"));
    text_ctrl_info_cfgver = new wxTextCtrl(notebook_ac_pane_info, -1, wxT("2.0"), wxDefaultPosition, wxDefaultSize, wxTE_READONLY);
    label_info_ver = new wxStaticText(notebook_ac_pane_info, -1, _("Flight Model Version"));
    text_ctrl_info_ver = new wxTextCtrl(notebook_ac_pane_info, -1, wxT("0.1"));
    label_info_author = new wxStaticText(notebook_ac_pane_info, -1, _("Author"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_info_author = new wxTextCtrl(notebook_ac_pane_info, -1, wxT(""));
    label_info_email = new wxStaticText(notebook_ac_pane_info, -1, _("Email"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_info_email = new wxTextCtrl(notebook_ac_pane_info, -1, wxT(""));
    label_info_org = new wxStaticText(notebook_ac_pane_info, -1, _("Organization"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_info_org = new wxTextCtrl(notebook_ac_pane_info, -1, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxHSCROLL);
    label_info_date = new wxStaticText(notebook_ac_pane_info, -1, _("File Date"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_info_date = new wxTextCtrl(notebook_ac_pane_info, -1, wxT(""));
    label_info_desc = new wxStaticText(notebook_ac_pane_info, -1, _("Description"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_info_desc = new wxTextCtrl(notebook_ac_pane_info, -1, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxHSCROLL);
    label_info_refs = new wxStaticText(notebook_ac_pane_info, -1, _("References"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    grid_info_refs = new wxGrid(notebook_ac_pane_info, -1);
    label_info_limit = new wxStaticText(notebook_ac_pane_info, -1, _("Limitations"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_info_limit = new wxTextCtrl(notebook_ac_pane_info, -1, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
    label_info_notes = new wxStaticText(notebook_ac_pane_info, -1, _("Notes"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_info_notes = new wxTextCtrl(notebook_ac_pane_info, -1, wxT(""), wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE);
    label_wingarea = new wxStaticText(notebook_ac_pane_metrics, -1, _("wingarea(*) ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_wingarea = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, wxTE_RIGHT, wxTextValidator(wxFILTER_NUMERIC));
    const wxString combo_box_wingarea_choices[] = {
        wxT("M2"),
        wxT("FT2")
    };
    combo_box_wingarea = new wxComboBox(notebook_ac_pane_metrics, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_wingarea_choices, wxCB_DROPDOWN|wxCB_READONLY);
    label_htailarea = new wxStaticText(notebook_ac_pane_metrics, -1, _("htailarea ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_htailarea = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, wxTE_RIGHT, wxTextValidator(wxFILTER_NUMERIC));
    const wxString combo_box_htailarea_choices[] = {
        wxT("M2"),
        wxT("FT2")
    };
    combo_box_htailarea = new wxComboBox(notebook_ac_pane_metrics, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_htailarea_choices, wxCB_DROPDOWN|wxCB_READONLY);
    label_wingspan = new wxStaticText(notebook_ac_pane_metrics, -1, _("wingspan(*) ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_wingspan = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, wxTE_RIGHT, wxTextValidator(wxFILTER_NUMERIC));
    const wxString combo_box_wingspan_choices[] = {
        wxT("M"),
        wxT("FT")
    };
    combo_box_wingspan = new wxComboBox(notebook_ac_pane_metrics, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_wingspan_choices, wxCB_DROPDOWN|wxCB_READONLY);
    label_htailarm = new wxStaticText(notebook_ac_pane_metrics, -1, _("htailarm ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_htailarm = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, wxTE_RIGHT, wxTextValidator(wxFILTER_NUMERIC));
    const wxString combo_box_htailarm_choices[] = {
        wxT("M"),
        wxT("FT")
    };
    combo_box_htailarm = new wxComboBox(notebook_ac_pane_metrics, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_htailarm_choices, wxCB_DROPDOWN|wxCB_READONLY);
    label_chord = new wxStaticText(notebook_ac_pane_metrics, -1, _("chord(*) ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_chord = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, wxTE_RIGHT, wxTextValidator(wxFILTER_NUMERIC));
    const wxString combo_box_chord_choices[] = {
        wxT("M"),
        wxT("FT")
    };
    combo_box_chord = new wxComboBox(notebook_ac_pane_metrics, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_chord_choices, wxCB_DROPDOWN|wxCB_READONLY);
    label_vtailarea = new wxStaticText(notebook_ac_pane_metrics, -1, _("vtailarea ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_vtailarea = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, wxTE_RIGHT, wxTextValidator(wxFILTER_NUMERIC));
    const wxString combo_box_vtailarea_choices[] = {
        wxT("M2"),
        wxT("FT2")
    };
    combo_box_vtailarea = new wxComboBox(notebook_ac_pane_metrics, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_vtailarea_choices, wxCB_DROPDOWN|wxCB_READONLY);
    label_wincidence = new wxStaticText(notebook_ac_pane_metrics, -1, _("wing incidence ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_wincidence = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, wxTE_RIGHT, wxTextValidator(wxFILTER_NUMERIC));
    const wxString combo_box_wincidence_choices[] = {
        wxT("DEG")
    };
    combo_box_wincidence = new wxComboBox(notebook_ac_pane_metrics, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 1, combo_box_wincidence_choices, wxCB_DROPDOWN|wxCB_READONLY);
    label_vtailarm = new wxStaticText(notebook_ac_pane_metrics, -1, _("vtailarm ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_vtailarm = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, wxTE_RIGHT, wxTextValidator(wxFILTER_NUMERIC));
    const wxString combo_box_vtailarm_choices[] = {
        wxT("M"),
        wxT("FT")
    };
    combo_box_vtailarm = new wxComboBox(notebook_ac_pane_metrics, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_vtailarm_choices, wxCB_DROPDOWN|wxCB_READONLY);
    label_arp_x = new wxStaticText(notebook_ac_pane_metrics, -1, _("x ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_arp_x = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC));
    label_arp_y = new wxStaticText(notebook_ac_pane_metrics, -1, _("y ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_arp_y = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC));
    label_arp_z = new wxStaticText(notebook_ac_pane_metrics, -1, _("z ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_arp_z = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC));
    label_arp_unit = new wxStaticText(notebook_ac_pane_metrics, -1, _("unit :"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    const wxString combo_box_arp_unit_choices[] = {
        wxT("M"),
        wxT("FT"),
        wxT("IN")
    };
    combo_box_arp_unit = new wxComboBox(notebook_ac_pane_metrics, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 3, combo_box_arp_unit_choices, wxCB_DROPDOWN|wxCB_READONLY);
    label_ep_x = new wxStaticText(notebook_ac_pane_metrics, -1, _("x ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_ep_x = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC));
    label_ep_y = new wxStaticText(notebook_ac_pane_metrics, -1, _("y ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_ep_y = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC));
    label_ep_z = new wxStaticText(notebook_ac_pane_metrics, -1, _("z ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_ep_z = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC));
    label_ep_unit = new wxStaticText(notebook_ac_pane_metrics, -1, _("unit :"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    const wxString combo_box_ep_unit_choices[] = {
        wxT("M"),
        wxT("FT"),
        wxT("IN")
    };
    combo_box_ep_unit = new wxComboBox(notebook_ac_pane_metrics, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 3, combo_box_ep_unit_choices, wxCB_DROPDOWN|wxCB_READONLY);
    label_vrp_x = new wxStaticText(notebook_ac_pane_metrics, -1, _("x ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_vrp_x = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC));
    label_vrp_y = new wxStaticText(notebook_ac_pane_metrics, -1, _("y ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_vrp_y = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC));
    label_vrp_z = new wxStaticText(notebook_ac_pane_metrics, -1, _("z ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_vrp_z = new wxTextCtrl(notebook_ac_pane_metrics, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC));
    label_vrp_unit = new wxStaticText(notebook_ac_pane_metrics, -1, _("unit :"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    const wxString combo_box_vrp_unit_choices[] = {
        wxT("M"),
        wxT("FT"),
        wxT("IN")
    };
    combo_box_vrp_unit = new wxComboBox(notebook_ac_pane_metrics, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 3, combo_box_vrp_unit_choices, wxCB_DROPDOWN|wxCB_READONLY);
    label_mass = new wxStaticText(notebook_ac_pane_mass, -1, _("Empty Weight(*) ="));
    text_ctrl_mass = new wxTextCtrl(notebook_ac_pane_mass, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, wxTE_RIGHT, wxTextValidator(wxFILTER_NUMERIC));
    const wxString combo_box_mass_unit_choices[] = {
        wxT("KG"),
        wxT("N"),
        wxT("LBS")
    };
    combo_box_mass_unit = new wxComboBox(notebook_ac_pane_mass, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 3, combo_box_mass_unit_choices, wxCB_DROPDOWN|wxCB_READONLY);
    label_mass_x = new wxStaticText(notebook_ac_pane_mass, -1, _("x ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_mass_x = new wxTextCtrl(notebook_ac_pane_mass, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC));
    label_mass_y = new wxStaticText(notebook_ac_pane_mass, -1, _("y ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_mass_y = new wxTextCtrl(notebook_ac_pane_mass, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC));
    label_mass_z = new wxStaticText(notebook_ac_pane_mass, -1, _("z ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_mass_z = new wxTextCtrl(notebook_ac_pane_mass, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, 0, wxTextValidator(wxFILTER_NUMERIC));
    const wxString combo_box_mass_locunit_choices[] = {
        wxT("M"),
        wxT("FT"),
        wxT("IN")
    };
    combo_box_mass_locunit = new wxComboBox(notebook_ac_pane_mass, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 3, combo_box_mass_locunit_choices, wxCB_DROPDOWN|wxCB_READONLY);
    label_ixx = new wxStaticText(notebook_ac_pane_mass, -1, _("Ixx ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_ixx = new wxTextCtrl(notebook_ac_pane_mass, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, wxTE_RIGHT, wxTextValidator(wxFILTER_NUMERIC));
    const wxString combo_box_ixx_choices[] = {
        wxT("KG*M2"),
        wxT("SLUG*FT2")
    };
    combo_box_ixx = new wxComboBox(notebook_ac_pane_mass, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_ixx_choices, wxCB_DROPDOWN|wxCB_READONLY|wxCB_SIMPLE);
    label_ixz = new wxStaticText(notebook_ac_pane_mass, -1, _("Ixz ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_ixz = new wxTextCtrl(notebook_ac_pane_mass, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, wxTE_RIGHT, wxTextValidator(wxFILTER_NUMERIC));
    const wxString combo_box_ixz_choices[] = {
        wxT("KG*M2"),
        wxT("SLUG*FT2")
    };
    combo_box_ixz = new wxComboBox(notebook_ac_pane_mass, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_ixz_choices, wxCB_DROPDOWN|wxCB_READONLY|wxCB_SIMPLE);
    label_iyy = new wxStaticText(notebook_ac_pane_mass, -1, _("Iyy ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_iyy = new wxTextCtrl(notebook_ac_pane_mass, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, wxTE_RIGHT, wxTextValidator(wxFILTER_NUMERIC));
    const wxString combo_box_iyy_choices[] = {
        wxT("KG*M2"),
        wxT("SLUG*FT2")
    };
    combo_box_iyy = new wxComboBox(notebook_ac_pane_mass, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_iyy_choices, wxCB_DROPDOWN|wxCB_READONLY|wxCB_SIMPLE);
    label_iyz = new wxStaticText(notebook_ac_pane_mass, -1, _("Iyz ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_iyz = new wxTextCtrl(notebook_ac_pane_mass, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, wxTE_RIGHT, wxTextValidator(wxFILTER_NUMERIC));
    const wxString combo_box_iyz_choices[] = {
        wxT("KG*M2"),
        wxT("SLUG*FT2")
    };
    combo_box_iyz = new wxComboBox(notebook_ac_pane_mass, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_iyz_choices, wxCB_DROPDOWN|wxCB_READONLY|wxCB_SIMPLE);
    label_izz = new wxStaticText(notebook_ac_pane_mass, -1, _("Izz ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_izz = new wxTextCtrl(notebook_ac_pane_mass, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, wxTE_RIGHT, wxTextValidator(wxFILTER_NUMERIC));
    const wxString combo_box_izz_choices[] = {
        wxT("KG*M2"),
        wxT("SLUG*FT2")
    };
    combo_box_izz = new wxComboBox(notebook_ac_pane_mass, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_izz_choices, wxCB_DROPDOWN|wxCB_READONLY|wxCB_SIMPLE);
    label_ixy = new wxStaticText(notebook_ac_pane_mass, -1, _("Ixy ="), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_ixy = new wxTextCtrl(notebook_ac_pane_mass, -1, wxT("0"), wxDefaultPosition, wxDefaultSize, wxTE_RIGHT, wxTextValidator(wxFILTER_NUMERIC));
    const wxString combo_box_ixy_choices[] = {
        wxT("KG*M2"),
        wxT("SLUG*FT2")
    };
    combo_box_ixy = new wxComboBox(notebook_ac_pane_mass, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_ixy_choices, wxCB_DROPDOWN|wxCB_READONLY|wxCB_SIMPLE);
    const wxString list_box_pm_choices[] = {
        
    };
    list_box_pm = new wxListBox(notebook_ac_pane_mass, ID_PM_LIST, wxDefaultPosition, wxDefaultSize, 0, list_box_pm_choices, 0);
    button_pm_add = new wxButton(notebook_ac_pane_mass, ID_PM_ADD, _("Add a new point mass"));
    button_pm_del = new wxButton(notebook_ac_pane_mass, ID_PM_DEL, _("Delete the selected point mass"));
    list_ctrl_gr = new wxListBox(notebook_ac_pane_ground, ID_LISTBOX_GR, wxDefaultPosition, wxDefaultSize, 0, list_box_pm_choices, 0);
    button_gr_add = new wxButton(notebook_ac_pane_ground, ID_GR_ADD, _("Add"));
    button_gr_del = new wxButton(notebook_ac_pane_ground, ID_GR_DEL, _("Delete"));
    button_gr_detail = new wxButton(notebook_ac_pane_ground, ID_GR_DETAIL, _("Detail"));
    label_aeng = new wxStaticText(notebook_ac_pane_propulsion, -1, _("Available Engines"));
    list_ctrl_avail_engines = new wxListCtrl(notebook_ac_pane_propulsion, ID_AVAIL_ENGS, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxSUNKEN_BORDER|wxLC_SINGLE_SEL);
    button_avail_engines = new wxButton(notebook_ac_pane_propulsion, ID_NEW_ENGINE, _("New"));
    button_avail_engines->Enable(false);
    button_avail_engines->Show(false);
    label_seng = new wxStaticText(notebook_ac_pane_propulsion, -1, _("Subscribed Engine(s)(*)"));
    list_ctrl_sub_engines = new wxListCtrl(notebook_ac_pane_propulsion, ID_SUB_ENGS, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxSUNKEN_BORDER|wxLC_SINGLE_SEL);
    button_sub_engines = new wxButton(notebook_ac_pane_propulsion, ID_SUB_ENGINE, _("New Pair"));
    button_sub_engines_del = new wxButton(notebook_ac_pane_propulsion, ID_SUB_ENGINE_DEL, _("Delete Pair"));
    button_sub_engines_detail = new wxButton(notebook_ac_pane_propulsion, ID_SUB_ENGINE_DETAIL, _("Detail Pair"));
    label_thrust = new wxStaticText(notebook_ac_pane_propulsion, -1, _("Available Thrusters"));
    list_ctrl_avail_thruster = new wxListCtrl(notebook_ac_pane_propulsion, ID_AVAIL_THRT, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxSUNKEN_BORDER|wxLC_SINGLE_SEL);
    button_avail_thrt = new wxButton(notebook_ac_pane_propulsion, ID_NEW_THRT, _("New"));
    button_avail_thrt->Enable(false);
    button_avail_thrt->Show(false);
    label_tanks = new wxStaticText(notebook_ac_pane_propulsion, -1, _("Tanks"));
    list_ctrl_tanks = new wxListCtrl(notebook_ac_pane_propulsion, ID_TANKS, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxSUNKEN_BORDER|wxLC_SINGLE_SEL);
    button_tanks = new wxButton(notebook_ac_pane_propulsion, ID_NEW_TANK, _("New Tank"));
    button_tanks_del = new wxButton(notebook_ac_pane_propulsion, ID_TANK_DEL, _("Delete Tank"));
    button_tanks_detail = new wxButton(notebook_ac_pane_propulsion, ID_TANK_DETAIL, _("Detail Tank"));
    label_propulsion = new wxStaticText(notebook_ac_pane_propulsion, -1, _("tips: double clicked to show detail, press delete key to delete item."));
    notebook_ac_pane_fcs = new DiagramDocument(notebook_ac, -1);
    tree_ctrl_aerodynamics = new wxTreeCtrl(notebook_ac_pane_aero, TREE, wxDefaultPosition, wxDefaultSize, wxTR_HAS_BUTTONS|wxTR_DEFAULT_STYLE);
    label_output_name = new wxStaticText(notebook_ac_pane_output, -1, _("Name(*) :"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_output_name = new wxTextCtrl(notebook_ac_pane_output, -1, wxT("JSBout.csv"));
    label_output_type = new wxStaticText(notebook_ac_pane_output, -1, _("Type(*) :"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    const wxString combo_box_output_type_choices[] = {
        wxT("CSV"),
        wxT("TABULAR")
    };
    combo_box_output_type = new wxComboBox(notebook_ac_pane_output, -1, wxT(""), wxDefaultPosition, wxDefaultSize, 2, combo_box_output_type_choices, wxCB_DROPDOWN);
    label_output_rate = new wxStaticText(notebook_ac_pane_output, -1, _("Rate(*) :"), wxDefaultPosition, wxDefaultSize, wxALIGN_RIGHT);
    text_ctrl_output_rate = new wxTextCtrl(notebook_ac_pane_output, -1, wxT("100"));
    checkbox_output_simu = new wxCheckBox(notebook_ac_pane_output, -1, _("simulation"));
    checkbox_output_atmo = new wxCheckBox(notebook_ac_pane_output, -1, _("atmosphere"));
    checkbox_output_mass = new wxCheckBox(notebook_ac_pane_output, -1, _("massprops"));
    checkbox_output_sur = new wxCheckBox(notebook_ac_pane_output, -1, _("aerosurfaces"));
    checkbox_output_rates = new wxCheckBox(notebook_ac_pane_output, -1, _("rates"));
    checkbox_output_vel = new wxCheckBox(notebook_ac_pane_output, -1, _("velocities"));
    checkbox_output_forc = new wxCheckBox(notebook_ac_pane_output, -1, _("forces"));
    checkbox_output_moments = new wxCheckBox(notebook_ac_pane_output, -1, _("moments"));
    checkbox_output_pos = new wxCheckBox(notebook_ac_pane_output, -1, _("position"));
    checkbox_output_coeff = new wxCheckBox(notebook_ac_pane_output, -1, _("coefficients"));
    checkbox_output_ground = new wxCheckBox(notebook_ac_pane_output, -1, _("ground reactions"));
    checkbox_output_fcs = new wxCheckBox(notebook_ac_pane_output, -1, _("FCS"));
    checkbox_output_propulsion = new wxCheckBox(notebook_ac_pane_output, -1, _("propulsion"));
    const wxString list_box_output_adds_choices[] = {
        
    };
    list_box_output_adds = new wxListBox(notebook_ac_pane_output, -1, wxDefaultPosition, wxDefaultSize, 0, list_box_output_adds_choices, 0);
    text_ctrl_output = new wxTextCtrl(notebook_ac_pane_output, -1, wxT(""));
    button_output_choose = new wxButton(notebook_ac_pane_output, ID_OUTPUT_CHS, _("Choose"));
    button_output_add = new wxButton(notebook_ac_pane_output, ID_OUTPUT_ADD, _("Add"));
    button_output_del = new wxButton(notebook_ac_pane_output, ID_OUTPUT_DEL, _("Delete"));

    set_properties();
    init_dialog();
    do_layout();
    // end wxGlade
}


BEGIN_EVENT_TABLE(AircraftDialog, wxDialog)
    // begin wxGlade: AircraftDialog::event_table
    EVT_LISTBOX_DCLICK(ID_PM_LIST, AircraftDialog::OnDetailPMList)
    EVT_LISTBOX(ID_PM_LIST, AircraftDialog::OnSelectPMList)
    EVT_BUTTON(ID_PM_ADD, AircraftDialog::OnAddPM)
    EVT_BUTTON(ID_PM_DEL, AircraftDialog::OnDelPM)
    EVT_BUTTON(ID_GR_ADD, AircraftDialog::OnAddGR)
    EVT_BUTTON(ID_GR_DEL, AircraftDialog::OnDelGR)
    EVT_BUTTON(ID_GR_DETAIL, AircraftDialog::OnDetailGR)
    EVT_BUTTON(ID_NEW_ENGINE, AircraftDialog::OnNewAvailEng)
    EVT_BUTTON(ID_SUB_ENGINE, AircraftDialog::OnSubEng)
    EVT_BUTTON(ID_SUB_ENGINE_DEL, AircraftDialog::OnSubEngDel)
    EVT_BUTTON(ID_SUB_ENGINE_DETAIL, AircraftDialog::OnSubEngDetail)
    EVT_BUTTON(ID_NEW_THRT, AircraftDialog::OnNewAvailThrt)
    EVT_BUTTON(ID_NEW_TANK, AircraftDialog::OnNewTank)
    EVT_BUTTON(ID_TANK_DEL, AircraftDialog::OnTankDel)
    EVT_BUTTON(ID_TANK_DETAIL, AircraftDialog::OnTankDetailB)
    EVT_BUTTON(ID_OUTPUT_CHS, AircraftDialog::OnOutputChoose)
    EVT_BUTTON(ID_OUTPUT_ADD, AircraftDialog::OnOutputAdd)
    EVT_BUTTON(ID_OUTPUT_DEL, AircraftDialog::OnOutputDel)
    // end wxGlade
    EVT_CLOSE(AircraftDialog::OnClose)
    EVT_TOOL(wxID_CLOSE, AircraftDialog::OnCloseButton)
    EVT_TOOL(wxID_NEW, AircraftDialog::OnNewButton)
    EVT_TOOL(wxID_OPEN, AircraftDialog::OnOpenButton)
    EVT_TOOL(wxID_SAVE, AircraftDialog::OnSaveButton)
    EVT_TOOL(wxID_SAVEAS, AircraftDialog::OnSaveAsButton)
    EVT_LISTBOX_DCLICK(ID_LISTBOX_GR, AircraftDialog::OnDetailGR)
    EVT_LIST_KEY_DOWN(ID_TANKS, AircraftDialog::OnTankDelete)
    EVT_LIST_ITEM_ACTIVATED(ID_TANKS, AircraftDialog::OnTankDetail) 
    EVT_LIST_ITEM_ACTIVATED(ID_SUB_ENGS, AircraftDialog::OnEngineDetail) 
    EVT_LIST_KEY_DOWN(ID_SUB_ENGS, AircraftDialog::OnEngineDelete)
END_EVENT_TABLE();


void AircraftDialog::OnDetailPMList(wxCommandEvent &event)
{
  int i;
  if ( (i = list_box_pm->GetSelection()) != wxNOT_FOUND )
  {
    ClientData_pm * data = dynamic_cast<ClientData_pm *>(list_box_pm->GetClientObject(i));
    if (data)
    {
      PMDialog dlg(this, -1);
      dlg.Load(data);
      if (dlg.ShowModal() == wxID_OK)
      {
        dlg.Save(data);
        list_box_pm->SetString(i, data->GetText());
      }
    }
  }
}


void AircraftDialog::OnSelectPMList(wxCommandEvent &event)
{
    event.Skip();
}


void AircraftDialog::OnAddPM(wxCommandEvent &event)
{
    ClientData_pm * data = new ClientData_pm;
    int i = list_box_pm->Append(data->GetText(), data);
    PMDialog dlg(this, -1);
    dlg.Load(data);
    if (dlg.ShowModal() == wxID_OK)
    {
        dlg.Save(data);
        list_box_pm->SetString(i, data->GetText());
    }
    list_box_pm->SetSelection(i);
}


void AircraftDialog::OnDelPM(wxCommandEvent &event)
{
  int i;
  if ( (i = list_box_pm->GetSelection()) != wxNOT_FOUND )
  {
    if ( ::wxMessageBox(_("Do you really want to delete it?"), _("Confirm"), wxYES_NO | wxICON_QUESTION, this) == wxYES )
    {
      list_box_pm->Delete(i);
    }
  }
}


void AircraftDialog::OnAddGR(wxCommandEvent &event)
{
    ClientData_LGear * data = new ClientData_LGear;
    int i = list_ctrl_gr->Append(data->GetText(), data);
    LGearDialog dlg(this, -1);
    dlg.Load(data);
    if (dlg.ShowModal() == wxID_OK)
    {
      dlg.Save(data);
      list_ctrl_gr->SetString(i, data->GetText());
    }
    list_ctrl_gr->SetSelection(i);
}


void AircraftDialog::OnDelGR(wxCommandEvent &event)
{
  int i;
  if ( (i = list_ctrl_gr->GetSelection()) != wxNOT_FOUND )
  {
    if ( ::wxMessageBox(_("Do you really want to delete it?"), _("Confirm"), wxYES_NO | wxICON_QUESTION, this) == wxYES )
    {
      list_ctrl_gr->Delete(i);
    }
  }
}


void AircraftDialog::OnDetailGR(wxCommandEvent &event)
{
  int i;
  if ( (i = list_ctrl_gr->GetSelection()) != wxNOT_FOUND )
  {
    ClientData_LGear * data = dynamic_cast<ClientData_LGear *>(list_ctrl_gr->GetClientObject(i));
    if (data)
    {
      LGearDialog dlg(this, -1);
      dlg.Load(data);
      if (dlg.ShowModal() == wxID_OK)
      {
        dlg.Save(data);
        list_ctrl_gr->SetString(i, data->GetText());
      }
    }
  }
}


void AircraftDialog::OnNewAvailEng(wxCommandEvent &event)
{
    event.Skip();
}


void AircraftDialog::OnSubEng(wxCommandEvent &event)
{
  wxString engine;
  int image_e;
  {
    long i = list_ctrl_avail_engines->GetSelectedItemCount();
    if ( i == 1 )
    {
        long item = -1;    
        item = list_ctrl_avail_engines->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
        if ( item == -1 )
        {
          return;
        }
        else
        {
          wxListItem list_item;
	  list_item.SetMask(wxLIST_MASK_IMAGE|wxLIST_MASK_DATA|wxLIST_MASK_TEXT);
          list_item.m_itemId = item;
          list_item.m_col = 0;
          if (list_ctrl_avail_engines->GetItem(list_item))
	  {
            engine = list_item.m_text;
            image_e = list_item.m_image;
	  }
	  else
	  {
	    return;
	  }
        }
    }
    else
    {
      return;
    }
  }
  wxString thruster;
  int image_t;
  {
    long i = list_ctrl_avail_thruster->GetSelectedItemCount();
    if ( i == 1 )
    {
        long item = -1;    
        item = list_ctrl_avail_thruster->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
        if ( item == -1 )
        {
          return;
        }
        else
        {
          wxListItem list_item;
	  list_item.SetMask(wxLIST_MASK_IMAGE|wxLIST_MASK_DATA|wxLIST_MASK_TEXT);
          list_item.m_itemId = item;
          list_item.m_col = 0;
          if (list_ctrl_avail_thruster->GetItem(list_item))
	  {
            thruster = list_item.m_text;
            image_t = list_item.m_image;
	  }
	  else
	  {
	    return;
	  }
        }
    }
    else
    {
      return;
    }
  }

  ClientData_engine data(engine, thruster);
  engines.push_back(data);
  long no = list_ctrl_sub_engines->GetItemCount();
  list_ctrl_sub_engines->InsertItem(no, data.GetEngineName(), image_e);
  list_ctrl_sub_engines->SetItemData(no, engines.size()-1);
  list_ctrl_sub_engines->SetItem(no, 1, data.GetThrusterName(), image_t);
  list_ctrl_sub_engines->SetColumnWidth( 0, wxLIST_AUTOSIZE );
  list_ctrl_sub_engines->SetColumnWidth( 1, wxLIST_AUTOSIZE );
    
    EngineThrusterDialog dlg(this, -1);
    dlg.Load(&(engines.back()));
    if (dlg.ShowModal() == wxID_OK)
    {
      dlg.Save(&(engines.back()));

      int image;
      wxListItem item;
      item.SetMask(wxLIST_MASK_IMAGE|wxLIST_MASK_DATA|wxLIST_MASK_TEXT);
      {
        long tmp = list_ctrl_avail_engines->FindItem(-1, engines.back().GetEngineName());
        if (tmp >=0 )
        {
          item.m_itemId = tmp;
          item.m_col = 0;
          list_ctrl_avail_engines->GetItem(item);
          image = item.m_image;
        }
        else
        {
          image = -1;
        }
      }
      list_ctrl_sub_engines->SetItem(no, 0, engines.back().GetEngineName(), image);
      {
        long tmp = list_ctrl_avail_thruster->FindItem(-1, engines.back().GetThrusterName());
        if (tmp >=0 )
        {
          item.m_itemId = tmp;
          item.m_col = 0;
          list_ctrl_avail_thruster->GetItem(item);
          image = item.m_image;
        }
        else
        {
          image = -1;
        }
      }
      list_ctrl_sub_engines->SetItem(no, 1, engines.back().GetThrusterName(), image);
      list_ctrl_sub_engines->SetColumnWidth( 0, wxLIST_AUTOSIZE );
      list_ctrl_sub_engines->SetColumnWidth( 1, wxLIST_AUTOSIZE );
    }
}


void AircraftDialog::OnNewAvailThrt(wxCommandEvent &event)
{
    event.Skip();
}


void AircraftDialog::OnNewTank(wxCommandEvent &event)
{
    ClientData_tank tank;
    tanks.push_back(tank);
    long no = list_ctrl_tanks->GetItemCount();
    list_ctrl_tanks->InsertItem(no, tank.GetText(), 35);
    list_ctrl_tanks->SetItemData(no, tanks.size()-1);
    list_ctrl_tanks->SetColumnWidth( 0, wxLIST_AUTOSIZE );
    
    TankDialog dlg(this, -1);
    dlg.Load(&(tanks.back()));
    if (dlg.ShowModal() == wxID_OK)
    {
      dlg.Save(&(tanks.back()));
      list_ctrl_tanks->SetItemText(no, tanks.back().GetText());
    }
}


void AircraftDialog::OnOutputChoose(wxCommandEvent &event)
{
  wxString tmp = text_ctrl_output->GetValue();
  GetPropertyDialog()->Select(tmp);
  if (GetPropertyDialog()->ShowModal() == wxID_OK)
  {
    text_ctrl_output->SetValue(GetPropertyDialog()->GetResult());
  }
}


void AircraftDialog::OnOutputAdd(wxCommandEvent &event)
{
  wxString tmp = text_ctrl_output->GetValue();
  if (!tmp.IsEmpty())
  {
    int i = list_box_output_adds->Append(tmp);
    text_ctrl_output->Clear();
    list_box_output_adds->SetSelection(i);
  }
}


void AircraftDialog::OnOutputDel(wxCommandEvent &event)
{
  int i = list_box_output_adds->GetSelection();
  if (i != wxNOT_FOUND)
  {
    if ( ::wxMessageBox(_("Do you really want to delete it?"), _("Confirm"), wxYES_NO | wxICON_QUESTION, this) == wxYES )
    {
      list_box_output_adds->Delete(i);
    }
  }
}


// wxGlade: add AircraftDialog event handlers

void AircraftDialog::OnClose(wxCloseEvent &event)
{
  if (event.CanVeto())
  {
    int rslt = wxMessageBox(_("Do you want to save the file before closing the dialog?"), _("Confirm"), wxYES_NO|wxCANCEL|wxICON_QUESTION, this);
    switch (rslt)
    {
    case wxYES :
      {
        wxCommandEvent e(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
        e.SetEventObject( this );
        GetEventHandler()->ProcessEvent(e);
      }
      break;
    case wxNO :
      {
        wxCommandEvent e(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
        e.SetEventObject( this );
        GetEventHandler()->ProcessEvent(e);
      }
      break;
    default :
      event.Veto();
    }
  }
  else
  {
    int rslt = wxMessageBox(_("Do you want to save the file before closing the dialog?"), _("Confirm"), wxYES_NO|wxICON_QUESTION, this);
    switch (rslt)
    {
    case wxYES :
      {
        wxCommandEvent e(wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK);
        e.SetEventObject( this );
        GetEventHandler()->ProcessEvent(e);
      }
      break;
    default :
      {
        wxCommandEvent e(wxEVT_COMMAND_BUTTON_CLICKED, wxID_CANCEL);
        e.SetEventObject( this );
        GetEventHandler()->ProcessEvent(e);
      }
    }
  }
}

void AircraftDialog::OnCloseButton(wxCommandEvent &event)
{
    wxCloseEvent e(wxEVT_CLOSE_WINDOW, wxID_CLOSE);
    e.SetEventObject( this );
    GetEventHandler()->ProcessEvent(e);
}

void AircraftDialog::OnNewButton(wxCommandEvent &event)
{
  {
    int rslt = wxMessageBox(_("Do you want to save the FDM configure file before creating another one?"), _("Confirm"), wxYES_NO|wxCANCEL|wxICON_QUESTION, this);
    if (rslt == wxYES)
    {
      Save();
    }
    else if (rslt == wxCANCEL)
    {
      return;
    }
  }
  {
    wxFileDialog dlg(this, _("Create FDM configure file"), wxT(""), wxT(""), wxT("XML file|*.xml"), wxSAVE|wxOVERWRITE_PROMPT);
    if (dlg.ShowModal() == wxID_OK)
    {
      mkNewFDMFile(dlg.GetPath());
      Load(dlg.GetPath());
    }
  }
}

void AircraftDialog::OnOpenButton(wxCommandEvent &event)
{
  {
    int rslt = wxMessageBox(_("Do you want to save the FDM configure file before opening another one?"), _("Confirm"), wxYES_NO|wxCANCEL|wxICON_QUESTION, this);
    if (rslt == wxYES)
    {
      Save();
    }
    else if (rslt == wxCANCEL)
    {
      return;
    }
  }
  {
    wxFileDialog dlg(this, _("Load FDM configure file"), wxT(""), wxT(""), wxT("XML file|*.xml"), wxOPEN|wxFILE_MUST_EXIST);
    if (dlg.ShowModal() == wxID_OK)
    {
      Load(dlg.GetPath());
    }
  }
}

void AircraftDialog::OnSaveButton(wxCommandEvent &event)
{
    int rslt = wxMessageBox(_("Do you want to save the FDM configure file?"), _("Confirm"), wxYES_NO|wxICON_QUESTION, this);
    if (rslt == wxYES)
    {
      Save();
    }
}

void AircraftDialog::OnSaveAsButton(wxCommandEvent &event)
{
  wxFileDialog dlg(this, _("Save FDM configure file as"), wxT(""), wxT(""), wxT("XML file|*.xml"), wxSAVE|wxOVERWRITE_PROMPT);
  if (dlg.ShowModal() == wxID_OK)
  {
    Save(dlg.GetPath());
  }
}

void AircraftDialog::OnTankDetailB(wxCommandEvent &event)
{
  wxListEvent e(wxEVT_COMMAND_LIST_ITEM_ACTIVATED , ID_TANKS);
  e.SetEventObject( this );
  GetEventHandler()->ProcessEvent(e);
}

void AircraftDialog::OnTankDetail(wxListEvent &event)
{
  long i = list_ctrl_tanks->GetSelectedItemCount();
  if ( i == 1 )
  {
    long item = -1;    
    item = list_ctrl_tanks->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
    if ( item == -1 )
      return;
    long data = list_ctrl_tanks->GetItemData(item);
    
    TankDialog dlg(this, -1);
    dlg.Load(&(tanks[data]));
    if (dlg.ShowModal() == wxID_OK)
    {
      dlg.Save(&(tanks[data]));
      list_ctrl_tanks->SetItemText(item, tanks[data].GetText());
    }
  }
}

void AircraftDialog::OnSubEngDetail(wxCommandEvent &event)
{
  wxListEvent e(wxEVT_COMMAND_LIST_ITEM_ACTIVATED , ID_SUB_ENGS);
  e.SetEventObject( this );
  GetEventHandler()->ProcessEvent(e);
}

void AircraftDialog::OnEngineDetail(wxListEvent &event)
{
  long i = list_ctrl_sub_engines->GetSelectedItemCount();
  if ( i == 1 )
  {
    long litem = -1;    
    litem = list_ctrl_sub_engines->GetNextItem(litem, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
    if ( litem == -1 )
      return;
    long data = list_ctrl_sub_engines->GetItemData(litem);
    
    EngineThrusterDialog dlg(this, -1);
    dlg.Load(&(engines[data]));
    if (dlg.ShowModal() == wxID_OK)
    {
      dlg.Save(&(engines[data]));

      int image;
      wxListItem item;
      item.SetMask(wxLIST_MASK_IMAGE|wxLIST_MASK_DATA|wxLIST_MASK_TEXT);
      {
        long tmp = list_ctrl_avail_engines->FindItem(-1, engines[data].GetEngineName());
        if (tmp >=0 )
        {
          item.m_itemId = tmp;
          item.m_col = 0;
          list_ctrl_avail_engines->GetItem(item);
          image = item.m_image;
        }
        else
        {
          image = -1;
        }
      }
      list_ctrl_sub_engines->SetItem(litem, 0, engines[data].GetEngineName(), image);
      {
        long tmp = list_ctrl_avail_thruster->FindItem(-1, engines[data].GetThrusterName());
        if (tmp >=0 )
        {
          item.m_itemId = tmp;
          item.m_col = 0;
          list_ctrl_avail_thruster->GetItem(item);
          image = item.m_image;
        }
        else
        {
          image = -1;
        }
      }
      list_ctrl_sub_engines->SetItem(litem, 1, engines[data].GetThrusterName(), image);
      list_ctrl_sub_engines->SetColumnWidth( 0, wxLIST_AUTOSIZE );
      list_ctrl_sub_engines->SetColumnWidth( 1, wxLIST_AUTOSIZE );
    }
  }
}

void AircraftDialog::OnTankDel(wxCommandEvent &event)
{
  wxListEvent e(wxEVT_COMMAND_LIST_KEY_DOWN , ID_TANKS);
  e.SetEventObject( this );
  e.m_code = WXK_DELETE;
  GetEventHandler()->ProcessEvent(e);
}

void AircraftDialog::OnTankDelete(wxListEvent &event)
{
  if (event.GetKeyCode() == WXK_DELETE)
  {
    long i = list_ctrl_tanks->GetSelectedItemCount();
    if ( i == 1 )
    {
      if ( ::wxMessageBox(_("Do you really want to delete the tank?"), _("Confirm"), wxYES_NO | wxICON_QUESTION, this) == wxYES )
      {
        long item = -1;    
        item = list_ctrl_tanks->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
        if ( item == -1 )
          return;
        list_ctrl_tanks->DeleteItem(item);
      }
    }
  }
  else
  {
    event.Skip();
  }
}

void AircraftDialog::OnSubEngDel(wxCommandEvent &event)
{
  wxListEvent e(wxEVT_COMMAND_LIST_KEY_DOWN , ID_SUB_ENGS);
  e.SetEventObject( this );
  e.m_code = WXK_DELETE;
  GetEventHandler()->ProcessEvent(e);
}

void AircraftDialog::OnEngineDelete(wxListEvent &event)
{
  if (event.GetKeyCode() == WXK_DELETE)
  {
    long i = list_ctrl_sub_engines->GetSelectedItemCount();
    if ( i == 1 )
    {
      if ( ::wxMessageBox(_("Do you really want to delete the engine/thruster pair?"), _("Confirm"), wxYES_NO | wxICON_QUESTION, this) == wxYES )
      {
        long item = -1;    
        item = list_ctrl_sub_engines->GetNextItem(item, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED);
        if ( item == -1 )
          return;
        list_ctrl_sub_engines->DeleteItem(item);
      }
    }
  }
  else
  {
    event.Skip();
  }
}


void AircraftDialog::set_properties()
{
    // begin wxGlade: AircraftDialog::set_properties
    SetMinSize(wxSize(800, 600));
    label_info_name->SetMinSize(wxSize(120, -1));
    text_ctrl_info_name->SetMinSize(wxSize(150, -1));
    text_ctrl_info_name->SetToolTip(_("the aircraft name"));
    text_ctrl_info_file->SetToolTip(_("the path of the aircraft model file"));
    label_info_level->SetMinSize(wxSize(120, -1));
    combo_box_info_level->SetToolTip(_("the release level"));
    combo_box_info_level->SetSelection(0);
    text_ctrl_info_cfgver->SetToolTip(_("the file format standard"));
    text_ctrl_info_ver->SetToolTip(_("the flight model version"));
    label_info_author->SetMinSize(wxSize(120, -1));
    text_ctrl_info_author->SetMinSize(wxSize(200, -1));
    text_ctrl_info_author->SetToolTip(_("the author name"));
    label_info_email->SetMinSize(wxSize(100, -1));
    text_ctrl_info_email->SetToolTip(_("the author's email address"));
    label_info_org->SetMinSize(wxSize(120, -1));
    text_ctrl_info_org->SetMinSize(wxSize(200, -1));
    text_ctrl_info_org->SetToolTip(_("the organization name"));
    label_info_date->SetMinSize(wxSize(120, -1));
    text_ctrl_info_date->SetMinSize(wxSize(200, -1));
    text_ctrl_info_date->SetToolTip(_("the date when the file is created or modified"));
    label_info_desc->SetMinSize(wxSize(100, -1));
    label_info_refs->SetMinSize(wxSize(120, -1));
    grid_info_refs->CreateGrid(10, 4);
    grid_info_refs->SetRowLabelSize(30);
    grid_info_refs->SetColLabelSize(30);
    grid_info_refs->SetColLabelValue(0, _("Ref ID."));
    grid_info_refs->SetColSize(0, 100);
    grid_info_refs->SetColLabelValue(1, _("Author"));
    grid_info_refs->SetColSize(1, 150);
    grid_info_refs->SetColLabelValue(2, _("Title"));
    grid_info_refs->SetColSize(2, 250);
    grid_info_refs->SetColLabelValue(3, _("Date"));
    grid_info_refs->SetColSize(3, 100);
    grid_info_refs->SetToolTip(_("References"));
    label_info_limit->SetMinSize(wxSize(120, -1));
    label_info_notes->SetMinSize(wxSize(120, -1));
    label_wingarea->SetMinSize(wxSize(150, -1));
    text_ctrl_wingarea->SetToolTip(_("the wing area (metrics/Sm*)"));
    combo_box_wingarea->SetMinSize(wxSize(60, -1));
    combo_box_wingarea->SetSelection(0);
    label_htailarea->SetMinSize(wxSize(150, -1));
    text_ctrl_htailarea->SetToolTip(_("the horizonal tail area (metrics/Sh-*)"));
    combo_box_htailarea->SetMinSize(wxSize(60, -1));
    combo_box_htailarea->SetSelection(0);
    label_wingspan->SetMinSize(wxSize(150, -1));
    text_ctrl_wingspan->SetToolTip(_("the wing span (metrics/bw-*)"));
    combo_box_wingspan->SetMinSize(wxSize(60, -1));
    combo_box_wingspan->SetSelection(0);
    label_htailarm->SetMinSize(wxSize(150, -1));
    text_ctrl_htailarm->SetToolTip(_("the horizonal tail arm (metrics/lh-*)"));
    combo_box_htailarm->SetMinSize(wxSize(60, -1));
    combo_box_htailarm->SetSelection(0);
    label_chord->SetMinSize(wxSize(150, -1));
    text_ctrl_chord->SetToolTip(_("the chord (metrics/cbarw-*)"));
    combo_box_chord->SetMinSize(wxSize(60, -1));
    combo_box_chord->SetSelection(0);
    label_vtailarea->SetMinSize(wxSize(150, -1));
    text_ctrl_vtailarea->SetToolTip(_("the vertical tail area (metrics/Sv-*)"));
    combo_box_vtailarea->SetMinSize(wxSize(60, -1));
    combo_box_vtailarea->SetSelection(0);
    label_wincidence->SetMinSize(wxSize(150, -1));
    text_ctrl_wincidence->SetToolTip(_("the wing incidence (metrics/iw-deg)"));
    combo_box_wincidence->SetMinSize(wxSize(60, -1));
    combo_box_wincidence->SetSelection(0);
    label_vtailarm->SetMinSize(wxSize(150, -1));
    text_ctrl_vtailarm->SetToolTip(_("the vertical tail arm (metrics/lv-*)"));
    combo_box_vtailarm->SetMinSize(wxSize(60, -1));
    combo_box_vtailarm->SetSelection(0);
    text_ctrl_arp_x->SetToolTip(_("the ARP along the structural x axis"));
    text_ctrl_arp_y->SetToolTip(_("the ARP along the structural y axis"));
    text_ctrl_arp_z->SetToolTip(_("the ARP along the structural z axis"));
    combo_box_arp_unit->SetMinSize(wxSize(60, -1));
    combo_box_arp_unit->SetSelection(0);
    text_ctrl_ep_x->SetToolTip(_("the EP along the structural x axis"));
    text_ctrl_ep_y->SetToolTip(_("the EP along the structural y axis"));
    text_ctrl_ep_z->SetToolTip(_("the EP along the structural z axis"));
    combo_box_ep_unit->SetMinSize(wxSize(60, -1));
    combo_box_ep_unit->SetSelection(0);
    text_ctrl_vrp_x->SetToolTip(_("the VRP along the structural x axis"));
    text_ctrl_vrp_y->SetToolTip(_("the VRP along the structural y axis"));
    text_ctrl_vrp_z->SetToolTip(_("the VRP along the structural z axis"));
    combo_box_vrp_unit->SetMinSize(wxSize(60, -1));
    combo_box_vrp_unit->SetSelection(0);
    text_ctrl_mass->SetMinSize(wxSize(120, -1));
    text_ctrl_mass->SetToolTip(_("the empty weight of the aircraft"));
    combo_box_mass_unit->SetMinSize(wxSize(60, -1));
    combo_box_mass_unit->SetSelection(0);
    label_mass_x->SetMinSize(wxSize(60, -1));
    text_ctrl_mass_x->SetMinSize(wxSize(100, -1));
    text_ctrl_mass_x->SetToolTip(_("the CG pos along the structural x axis"));
    label_mass_y->SetMinSize(wxSize(60, -1));
    text_ctrl_mass_y->SetMinSize(wxSize(100, -1));
    text_ctrl_mass_y->SetToolTip(_("the CG pos along the structural y axis"));    label_mass_z->SetMinSize(wxSize(60, -1));
    text_ctrl_mass_z->SetMinSize(wxSize(100, -1));
    text_ctrl_mass_z->SetToolTip(_("the CG pos along the structural z axis"));    combo_box_mass_locunit->SetMinSize(wxSize(60, -1));
    combo_box_mass_locunit->SetSelection(0);
    label_ixx->SetMinSize(wxSize(120, -1));
    text_ctrl_ixx->SetMinSize(wxSize(120, -1));
    combo_box_ixx->SetMinSize(wxSize(100, -1));
    combo_box_ixx->SetSelection(0);
    label_ixz->SetMinSize(wxSize(120, -1));
    text_ctrl_ixz->SetMinSize(wxSize(120, -1));
    combo_box_ixz->SetMinSize(wxSize(100, -1));
    combo_box_ixz->SetSelection(0);
    label_iyy->SetMinSize(wxSize(120, -1));
    text_ctrl_iyy->SetMinSize(wxSize(120, -1));
    combo_box_iyy->SetMinSize(wxSize(100, -1));
    combo_box_iyy->SetSelection(0);
    label_iyz->SetMinSize(wxSize(120, -1));
    text_ctrl_iyz->SetMinSize(wxSize(120, -1));
    combo_box_iyz->SetMinSize(wxSize(100, -1));
    combo_box_iyz->SetSelection(0);
    label_izz->SetMinSize(wxSize(120, -1));
    text_ctrl_izz->SetMinSize(wxSize(120, -1));
    combo_box_izz->SetMinSize(wxSize(100, -1));
    combo_box_izz->SetSelection(0);
    label_ixy->SetMinSize(wxSize(120, -1));
    text_ctrl_ixy->SetMinSize(wxSize(120, -1));
    combo_box_ixy->SetMinSize(wxSize(100, -1));
    combo_box_ixy->SetSelection(0);
    list_box_pm->SetToolTip(_("double click on me to show detail"));
    list_ctrl_sub_engines->SetToolTip(_("double clicked on me to show detail, \npress delete key to delete a subscribed engine"));
    button_sub_engines->SetToolTip(_("choose an available engine and an available thruster, \nthen click on me to subscribe a new engine for the aircraft"));
    button_sub_engines_del->SetToolTip(_("choose a subscribed engine, then click on me to delete it"));
    button_sub_engines_detail->SetToolTip(_("choose a subscribed engine, then click on me to show the detail"));
    list_ctrl_tanks->SetToolTip(_("double clicked on me to show detail, \npress delete key to delete a tank"));
    button_tanks->SetToolTip(_("click on me to add a new tank for the aircraft"));
    button_tanks_del->SetToolTip(_("click on me to delete a tank"));
    button_tanks_detail->SetToolTip(_("click on me to show the detail of the tank"));
    label_output_name->SetMinSize(wxSize(120, -1));
    text_ctrl_output_name->SetMinSize(wxSize(200, -1));
    label_output_type->SetMinSize(wxSize(120, -1));
    combo_box_output_type->SetMinSize(wxSize(100, -1));
    combo_box_output_type->SetSelection(0);
    label_output_rate->SetMinSize(wxSize(120, -1));
    text_ctrl_output_rate->SetMinSize(wxSize(80, -1));
    list_box_output_adds->SetToolTip(_("addition properties which will be outputed."));
    // end wxGlade
}


void AircraftDialog::do_layout()
{
    // begin wxGlade: AircraftDialog::do_layout
    wxBoxSizer* sizer_1 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_21 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_22 = new wxBoxSizer(wxHORIZONTAL);
    wxGridSizer* grid_sizer_2 = new wxGridSizer(4, 4, 5, 5);
    wxFlexGridSizer* grid_sizer_1 = new wxFlexGridSizer(3, 2, 10, 5);
    wxBoxSizer* sizer_20 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_14 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_24 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_15_copy_2 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_15_copy_1 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_15_copy = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_15 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_16 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_17 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_massbalance = new wxBoxSizer(wxVERTICAL);
    wxStaticBoxSizer* sizer_pm = new wxStaticBoxSizer(sizer_pm_staticbox, wxVERTICAL);
    wxBoxSizer* sizer_pmb = new wxBoxSizer(wxHORIZONTAL);
    wxStaticBoxSizer* sizer_moment = new wxStaticBoxSizer(sizer_moment_staticbox, wxVERTICAL);
    wxFlexGridSizer* grid_sizer_moment = new wxFlexGridSizer(6, 6, 6, 5);
    wxStaticBoxSizer* sizer_mass = new wxStaticBoxSizer(sizer_mass_staticbox, wxVERTICAL);
    wxStaticBoxSizer* sizer_massloc = new wxStaticBoxSizer(sizer_massloc_staticbox, wxHORIZONTAL);
    wxBoxSizer* sizer_ew = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_13 = new wxBoxSizer(wxVERTICAL);
    wxStaticBoxSizer* sizer_vrp = new wxStaticBoxSizer(sizer_vrp_staticbox, wxHORIZONTAL);
    wxStaticBoxSizer* sizer_ep = new wxStaticBoxSizer(sizer_ep_staticbox, wxHORIZONTAL);
    wxStaticBoxSizer* sizer_arp = new wxStaticBoxSizer(sizer_arp_staticbox, wxHORIZONTAL);
    wxFlexGridSizer* grid_sizer_matrics = new wxFlexGridSizer(4, 6, 20, 5);
    wxBoxSizer* sizer_2 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_12 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_11 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_10 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_6 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_7 = new wxBoxSizer(wxVERTICAL);
    wxBoxSizer* sizer_9 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_8 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_5 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_4 = new wxBoxSizer(wxHORIZONTAL);
    wxBoxSizer* sizer_3 = new wxBoxSizer(wxHORIZONTAL);
    sizer_3->Add(label_info_name, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_3->Add(text_ctrl_info_name, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_3->Add(label_info_file, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_3->Add(text_ctrl_info_file, 1, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_2->Add(sizer_3, 0, wxTOP|wxBOTTOM|wxEXPAND, 5);
    sizer_4->Add(label_info_level, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_4->Add(combo_box_info_level, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_4->Add(label_info_cfgver, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_4->Add(text_ctrl_info_cfgver, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_4->Add(label_info_ver, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_4->Add(text_ctrl_info_ver, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_2->Add(sizer_4, 0, wxTOP|wxBOTTOM|wxEXPAND, 5);
    sizer_5->Add(label_info_author, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_5->Add(text_ctrl_info_author, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_5->Add(label_info_email, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_5->Add(text_ctrl_info_email, 1, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_2->Add(sizer_5, 0, wxTOP|wxBOTTOM|wxEXPAND, 5);
    sizer_8->Add(label_info_org, 0, wxLEFT|wxRIGHT, 5);
    sizer_8->Add(text_ctrl_info_org, 1, wxRIGHT|wxEXPAND, 5);
    sizer_7->Add(sizer_8, 1, wxTOP|wxBOTTOM|wxEXPAND, 5);
    sizer_9->Add(label_info_date, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_9->Add(text_ctrl_info_date, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_7->Add(sizer_9, 0, wxTOP|wxBOTTOM|wxEXPAND, 5);
    sizer_6->Add(sizer_7, 0, wxEXPAND, 0);
    sizer_6->Add(label_info_desc, 0, wxLEFT|wxRIGHT, 5);
    sizer_6->Add(text_ctrl_info_desc, 1, wxTOP|wxBOTTOM|wxEXPAND, 5);
    sizer_2->Add(sizer_6, 2, wxEXPAND, 0);
    sizer_10->Add(label_info_refs, 0, wxLEFT|wxRIGHT, 5);
    sizer_10->Add(grid_info_refs, 1, wxRIGHT|wxEXPAND, 5);
    sizer_2->Add(sizer_10, 2, wxTOP|wxBOTTOM|wxEXPAND, 5);
    sizer_11->Add(label_info_limit, 0, wxLEFT|wxRIGHT, 5);
    sizer_11->Add(text_ctrl_info_limit, 1, wxRIGHT|wxEXPAND, 5);
    sizer_2->Add(sizer_11, 1, wxTOP|wxBOTTOM|wxEXPAND, 5);
    sizer_12->Add(label_info_notes, 0, wxLEFT|wxRIGHT, 5);
    sizer_12->Add(text_ctrl_info_notes, 1, wxRIGHT|wxEXPAND, 5);
    sizer_2->Add(sizer_12, 1, wxEXPAND, 0);
    notebook_ac_pane_info->SetAutoLayout(true);
    notebook_ac_pane_info->SetSizer(sizer_2);
    sizer_2->Fit(notebook_ac_pane_info);
    sizer_2->SetSizeHints(notebook_ac_pane_info);
    grid_sizer_matrics->Add(label_wingarea, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(text_ctrl_wingarea, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(combo_box_wingarea, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(label_htailarea, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 10);
    grid_sizer_matrics->Add(text_ctrl_htailarea, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(combo_box_htailarea, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(label_wingspan, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(text_ctrl_wingspan, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(combo_box_wingspan, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(label_htailarm, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 10);
    grid_sizer_matrics->Add(text_ctrl_htailarm, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(combo_box_htailarm, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(label_chord, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(text_ctrl_chord, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(combo_box_chord, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(label_vtailarea, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 10);
    grid_sizer_matrics->Add(text_ctrl_vtailarea, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(combo_box_vtailarea, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(label_wincidence, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(text_ctrl_wincidence, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(combo_box_wincidence, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(label_vtailarm, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 10);
    grid_sizer_matrics->Add(text_ctrl_vtailarm, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_matrics->Add(combo_box_vtailarm, 0, wxALIGN_CENTER_VERTICAL, 0);
    sizer_13->Add(grid_sizer_matrics, 0, wxTOP|wxBOTTOM|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 20);
    sizer_arp->Add(label_arp_x, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_arp->Add(text_ctrl_arp_x, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_arp->Add(label_arp_y, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_arp->Add(text_ctrl_arp_y, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_arp->Add(label_arp_z, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_arp->Add(text_ctrl_arp_z, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_arp->Add(label_arp_unit, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_arp->Add(combo_box_arp_unit, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_13->Add(sizer_arp, 1, wxALL|wxEXPAND, 5);
    sizer_ep->Add(label_ep_x, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_ep->Add(text_ctrl_ep_x, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_ep->Add(label_ep_y, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_ep->Add(text_ctrl_ep_y, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_ep->Add(label_ep_z, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_ep->Add(text_ctrl_ep_z, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_ep->Add(label_ep_unit, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_ep->Add(combo_box_ep_unit, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_13->Add(sizer_ep, 1, wxALL|wxEXPAND, 5);
    sizer_vrp->Add(label_vrp_x, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_vrp->Add(text_ctrl_vrp_x, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_vrp->Add(label_vrp_y, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_vrp->Add(text_ctrl_vrp_y, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_vrp->Add(label_vrp_z, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_vrp->Add(text_ctrl_vrp_z, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_vrp->Add(label_vrp_unit, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_vrp->Add(combo_box_vrp_unit, 0, wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_13->Add(sizer_vrp, 1, wxALL|wxEXPAND, 5);
    notebook_ac_pane_metrics->SetAutoLayout(true);
    notebook_ac_pane_metrics->SetSizer(sizer_13);
    sizer_13->Fit(notebook_ac_pane_metrics);
    sizer_13->SetSizeHints(notebook_ac_pane_metrics);
    sizer_ew->Add(label_mass, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_ew->Add(text_ctrl_mass, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_ew->Add(combo_box_mass_unit, 0, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_mass->Add(sizer_ew, 0, wxTOP|wxBOTTOM|wxALIGN_CENTER_HORIZONTAL, 5);
    sizer_massloc->Add(label_mass_x, 1, wxALIGN_CENTER_VERTICAL, 0);
    sizer_massloc->Add(text_ctrl_mass_x, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
    sizer_massloc->Add(label_mass_y, 1, wxALIGN_CENTER_VERTICAL, 0);
    sizer_massloc->Add(text_ctrl_mass_y, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
    sizer_massloc->Add(label_mass_z, 1, wxALIGN_CENTER_VERTICAL, 0);
    sizer_massloc->Add(text_ctrl_mass_z, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5);
    sizer_massloc->Add(combo_box_mass_locunit, 0, wxLEFT|wxALIGN_CENTER_VERTICAL, 30);
    sizer_massbalance->Add(sizer_mass, 0, wxALL|wxEXPAND, 5);
    sizer_massbalance->Add(sizer_massloc, 0, wxALL|wxEXPAND, 5);
    grid_sizer_moment->Add(label_ixx, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(text_ctrl_ixx, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(combo_box_ixx, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(label_ixz, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(text_ctrl_ixz, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(combo_box_ixz, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(label_iyy, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(text_ctrl_iyy, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(combo_box_iyy, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(label_iyz, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(text_ctrl_iyz, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(combo_box_iyz, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(label_izz, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(text_ctrl_izz, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(combo_box_izz, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(label_ixy, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(text_ctrl_ixy, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_moment->Add(combo_box_ixy, 0, wxALIGN_CENTER_VERTICAL, 0);
    sizer_moment->Add(grid_sizer_moment, 0, wxTOP|wxBOTTOM, 5);
    sizer_massbalance->Add(sizer_moment, 0, wxALL|wxEXPAND, 5);
    sizer_pm->Add(list_box_pm, 1, wxALL|wxEXPAND, 5);
    sizer_pmb->Add(button_pm_add, 1, 0, 0);
    sizer_pmb->Add(button_pm_del, 1, 0, 0);
    sizer_pm->Add(sizer_pmb, 0, wxALL|wxEXPAND, 5);
    sizer_massbalance->Add(sizer_pm, 1, wxALL|wxEXPAND, 5);
    notebook_ac_pane_mass->SetAutoLayout(true);
    notebook_ac_pane_mass->SetSizer(sizer_massbalance);
    sizer_massbalance->Fit(notebook_ac_pane_mass);
    sizer_massbalance->SetSizeHints(notebook_ac_pane_mass);
    sizer_16->Add(list_ctrl_gr, 1, wxALL|wxEXPAND, 5);
    sizer_17->Add(button_gr_add, 1, 0, 0);
    sizer_17->Add(button_gr_del, 1, 0, 0);
    sizer_17->Add(button_gr_detail, 1, 0, 0);
    sizer_16->Add(sizer_17, 0, wxALL|wxEXPAND, 5);
    notebook_ac_pane_ground->SetAutoLayout(true);
    notebook_ac_pane_ground->SetSizer(sizer_16);
    sizer_16->Fit(notebook_ac_pane_ground);
    sizer_16->SetSizeHints(notebook_ac_pane_ground);
    sizer_15->Add(label_aeng, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    sizer_15->Add(list_ctrl_avail_engines, 1, wxALL|wxEXPAND, 5);
    sizer_15->Add(button_avail_engines, 0, wxALL|wxEXPAND, 5);
    sizer_14->Add(sizer_15, 1, wxEXPAND, 0);
    sizer_15_copy_1->Add(label_thrust, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    sizer_15_copy_1->Add(list_ctrl_avail_thruster, 1, wxALL|wxEXPAND, 5);
    sizer_15_copy_1->Add(button_avail_thrt, 0, wxALL|wxEXPAND, 5);
    sizer_14->Add(sizer_15_copy_1, 1, wxEXPAND, 0);
    sizer_15_copy->Add(label_seng, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    sizer_15_copy->Add(list_ctrl_sub_engines, 1, wxALL|wxEXPAND, 5);
    sizer_15_copy->Add(button_sub_engines, 0, wxALL|wxEXPAND, 5);
    sizer_15_copy->Add(button_sub_engines_del, 0, wxALL|wxEXPAND, 5);
    sizer_15_copy->Add(button_sub_engines_detail, 0, wxALL|wxEXPAND, 5);
    sizer_14->Add(sizer_15_copy, 1, wxEXPAND, 0);
    sizer_15_copy_2->Add(label_tanks, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
    sizer_15_copy_2->Add(list_ctrl_tanks, 1, wxALL|wxEXPAND, 5);
    sizer_15_copy_2->Add(button_tanks, 0, wxALL|wxEXPAND, 5);
    sizer_15_copy_2->Add(button_tanks_del, 0, wxALL|wxEXPAND, 5);
    sizer_15_copy_2->Add(button_tanks_detail, 0, wxALL|wxEXPAND, 5);
    sizer_14->Add(sizer_15_copy_2, 1, wxEXPAND, 0);
    sizer_24->Add(sizer_14, 1, wxALL|wxEXPAND, 3);
    sizer_24->Add(label_propulsion, 0, wxALL|wxEXPAND, 3);
    notebook_ac_pane_propulsion->SetAutoLayout(true);
    notebook_ac_pane_propulsion->SetSizer(sizer_24);
    sizer_14->Fit(notebook_ac_pane_propulsion);
    sizer_14->SetSizeHints(notebook_ac_pane_propulsion);
    sizer_20->Add(tree_ctrl_aerodynamics, 1, wxALL|wxEXPAND, 5);
    notebook_ac_pane_aero->SetAutoLayout(true);
    notebook_ac_pane_aero->SetSizer(sizer_20);
    sizer_20->Fit(notebook_ac_pane_aero);
    sizer_20->SetSizeHints(notebook_ac_pane_aero);
    grid_sizer_1->Add(label_output_name, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_1->Add(text_ctrl_output_name, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_1->Add(label_output_type, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_1->Add(combo_box_output_type, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_1->Add(label_output_rate, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_1->Add(text_ctrl_output_rate, 0, wxALIGN_CENTER_VERTICAL, 0);
    sizer_21->Add(grid_sizer_1, 0, wxTOP|wxBOTTOM|wxALIGN_CENTER_HORIZONTAL, 5);
    grid_sizer_2->Add(checkbox_output_simu, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_2->Add(checkbox_output_atmo, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_2->Add(checkbox_output_mass, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_2->Add(checkbox_output_sur, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_2->Add(checkbox_output_rates, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_2->Add(checkbox_output_vel, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_2->Add(checkbox_output_forc, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_2->Add(checkbox_output_moments, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_2->Add(checkbox_output_pos, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_2->Add(checkbox_output_coeff, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_2->Add(checkbox_output_ground, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_2->Add(checkbox_output_fcs, 0, wxALIGN_CENTER_VERTICAL, 0);
    grid_sizer_2->Add(checkbox_output_propulsion, 0, wxALIGN_CENTER_VERTICAL, 0);
    sizer_21->Add(grid_sizer_2, 0, wxTOP|wxBOTTOM|wxALIGN_CENTER_HORIZONTAL, 10);
    sizer_21->Add(list_box_output_adds, 1, wxALL|wxEXPAND|wxALIGN_CENTER_HORIZONTAL, 10);
    sizer_22->Add(text_ctrl_output, 1, wxLEFT|wxRIGHT|wxALIGN_CENTER_VERTICAL, 5);
    sizer_22->Add(button_output_choose, 0, wxALIGN_CENTER_VERTICAL, 0);
    sizer_22->Add(button_output_add, 0, wxALIGN_CENTER_VERTICAL, 0);
    sizer_22->Add(button_output_del, 0, wxALIGN_CENTER_VERTICAL, 0);
    sizer_21->Add(sizer_22, 0, wxALL|wxEXPAND, 5);
    notebook_ac_pane_output->SetAutoLayout(true);
    notebook_ac_pane_output->SetSizer(sizer_21);
    sizer_21->Fit(notebook_ac_pane_output);
    sizer_21->SetSizeHints(notebook_ac_pane_output);
    notebook_ac->AddPage(notebook_ac_pane_info, _("General Information"));
    notebook_ac->AddPage(notebook_ac_pane_metrics, _("Metrics"));
    notebook_ac->AddPage(notebook_ac_pane_mass, _("Mass & Balance"));
    notebook_ac->AddPage(notebook_ac_pane_ground, _("Ground Reactions"));
    notebook_ac->AddPage(notebook_ac_pane_propulsion, _("Propulsion"));
    notebook_ac->AddPage(notebook_ac_pane_fcs, _("Flight Control"));
    notebook_ac->AddPage(notebook_ac_pane_aero, _("Aerodynamics"));
    notebook_ac->AddPage(notebook_ac_pane_output, _("Output"));
    sizer_1->Add(frame_ac_toolbar, 0, wxEXPAND|wxALL, 5);
    sizer_1->Add(notebook_ac, 1, wxEXPAND|wxALL, 5);
    SetAutoLayout(true);
    SetSizer(sizer_1);
    Layout();
    Centre();
    // end wxGlade
}

void AircraftDialog::init_dialog()
{
  TreeItemEvtHandler * tree_item_evt_handler = new TreeItemEvtHandler(tree_ctrl_aerodynamics);
  tree_item_evt_handler->FuncPrefix = wxT("aero/coefficient/C");
  tree_ctrl_aerodynamics->PushEventHandler(tree_item_evt_handler);

  wxBitmap bmp(wxBITMAP(fileheader_icon));
  wxImageList * images = new wxImageList(bmp.GetWidth(), bmp.GetHeight());
  images->Add(bmp); // 0
  images->Add(wxBITMAP(metrics_icon));
  images->Add(wxBITMAP(mass_icon));
  images->Add(wxBITMAP(gear_icon));
  images->Add(wxBITMAP(engine_icon));
  images->Add(wxBITMAP(ap_icon)); // 5
  images->Add(wxBITMAP(fcs_icon));
  images->Add(wxBITMAP(aero_icon));
  images->Add(wxBITMAP(output_icon));
  images->Add(wxBITMAP(axis));
  images->Add(wxBITMAP(operator_product)); //10
  images->Add(wxBITMAP(operator_difference));
  images->Add(wxBITMAP(operator_sum));
  images->Add(wxBITMAP(operator_quotient));
  images->Add(wxBITMAP(operator_pow));
  images->Add(wxBITMAP(operator_abs));   //15
  images->Add(wxBITMAP(operator_sin));
  images->Add(wxBITMAP(operator_cos));
  images->Add(wxBITMAP(operator_tan));
  images->Add(wxBITMAP(operator_asin));
  images->Add(wxBITMAP(operator_acos)); //20
  images->Add(wxBITMAP(operator_atan));
  images->Add(wxBITMAP(operator_derivative));
  images->Add(wxBITMAP(operator_integral));
  images->Add(wxBITMAP(operator_func));
  images->Add(wxBITMAP(property_icon));  //25
  images->Add(wxBITMAP(table_icon));
  images->Add(wxBITMAP(value_icon));
  images->Add(wxBITMAP(piston_engine));
  images->Add(wxBITMAP(turbine_engine));
  images->Add(wxBITMAP(rocket_engine));   //30
  images->Add(wxBITMAP(electric_engine));
  images->Add(wxBITMAP(propeller));
  images->Add(wxBITMAP(nozzle));
  images->Add(wxBITMAP(direct));
  images->Add(wxBITMAP(tank));  //35
  images->Add(wxBITMAP(operator_lt));
  images->Add(wxBITMAP(operator_le));
  images->Add(wxBITMAP(operator_gt));
  images->Add(wxBITMAP(operator_ge));
  images->Add(wxBITMAP(operator_eq));  //40
  images->Add(wxBITMAP(operator_ne));
  images->Add(wxBITMAP(operator_and));
  images->Add(wxBITMAP(operator_or));
  images->Add(wxBITMAP(operator_not));
  images->Add(wxBITMAP(operator_ifthen));  //45


  tree_ctrl_aerodynamics->AssignImageList(images);
  aerodynamics_data = new TreeItemData_aerodynamics;
  root = tree_ctrl_aerodynamics->AddRoot(wxT("aerodynamics"), 0, 0, aerodynamics_data);
  aerodynamics_data->Init(tree_ctrl_aerodynamics);

  list_ctrl_tanks->SetImageList(images, wxIMAGE_LIST_SMALL);
  list_ctrl_avail_engines->SetImageList(images, wxIMAGE_LIST_SMALL);
  list_ctrl_sub_engines->SetImageList(images, wxIMAGE_LIST_SMALL);
  list_ctrl_avail_thruster->SetImageList(images, wxIMAGE_LIST_SMALL);
  wxListItem itemCol;
  itemCol.SetText(_("Tank"));
  itemCol.SetImage(-1);
  list_ctrl_tanks->InsertColumn(0, itemCol);
  itemCol.SetText(_("Engine"));
  itemCol.SetImage(-1);
  list_ctrl_avail_engines->InsertColumn(0, itemCol);
  list_ctrl_sub_engines->InsertColumn(0, itemCol);
  itemCol.SetText(_("Thruster"));
  itemCol.SetImage(-1);
  list_ctrl_sub_engines->InsertColumn(1, itemCol);
  list_ctrl_avail_thruster->InsertColumn(0, itemCol);

  {
    wxFileConfig config(wxT("EngineMgr"), wxT("nuaa"), wxT("EngineMgr.ini"), wxT("EngineMgr.ini"), wxCONFIG_USE_LOCAL_FILE|wxCONFIG_USE_RELATIVE_PATH);
    long id = 76l;
    wxString engine_id;
    bool flag = config.GetFirstGroup(engine_id, id);
    long eNo = 0;
    long tNo = 0;
    while (flag)
    {
      wxString type;
      if ( config.Read(engine_id + wxT("/type"), &type) )
      {
        if (type == wxT("piston_engine"))
        {
          list_ctrl_avail_engines->InsertItem(eNo++, engine_id, 28);
        }
        else if (type == wxT("turbine_engine"))
        {
          list_ctrl_avail_engines->InsertItem(eNo++, engine_id, 29);
        }
        else if (type == wxT("rocket_engine"))
        {
          list_ctrl_avail_engines->InsertItem(eNo++, engine_id, 30);
        
        }
        else if (type == wxT("electric_engine"))
        {
          list_ctrl_avail_engines->InsertItem(eNo++, engine_id, 31);
        }
        else if (type == wxT("propeller"))
        {
          list_ctrl_avail_thruster->InsertItem(tNo++, engine_id, 32);
        }
        else if (type == wxT("nozzle"))
        {
          list_ctrl_avail_thruster->InsertItem(tNo++, engine_id, 33);       
        }
        else if (type == wxT("direct"))
        {
          list_ctrl_avail_thruster->InsertItem(tNo++, engine_id, 34);       
        }
      }
      flag = config.GetNextGroup(engine_id, id);
    }
  }

  list_ctrl_tanks->SetColumnWidth( 0, wxLIST_AUTOSIZE );
  list_ctrl_avail_engines->SetColumnWidth( 0, wxLIST_AUTOSIZE );
  list_ctrl_avail_thruster->SetColumnWidth( 0, wxLIST_AUTOSIZE );
  list_ctrl_sub_engines->SetColumnWidth( 0, wxLIST_AUTOSIZE );
  list_ctrl_sub_engines->SetColumnWidth( 1, wxLIST_AUTOSIZE );
}


bool AircraftDialog::Load(const wxString &fn)
{
  text_ctrl_info_file->SetValue(fn);

  bool flag = true;
  controls_file_parser = new JSBSim::FGXMLParse;
  try
  {
    readXML (fn.c_str(), *controls_file_parser);
  }
  catch (...)
  {
    flag = false;
  }

  JSBSim::Element * document=NULL;
  JSBSim::Element * tmp;
  JSBSim::Element * null_el= new JSBSim::Element("fdm_config");

  if (flag)
  {
    document = controls_file_parser->GetDocument();
    if (document->GetName() != "fdm_config")
      return false; //flag = false;
  }


  if (flag)
  {
    text_ctrl_info_name->SetValue(document->GetAttributeValue("name"));
    text_ctrl_info_cfgver->SetValue(document->GetAttributeValue("version"));
    combo_box_info_level->SetValue(document->GetAttributeValue("release"));
  }
  else
  {
    text_ctrl_info_name->SetValue(wxT("Unknown"));
    text_ctrl_info_cfgver->SetValue(wxT("2.0"));
    combo_box_info_level->SetValue(wxT("ALPHA"));  
  }
  
  {
    double d;
    if ( text_ctrl_info_cfgver->GetValue().ToDouble(&d) )
    {
      if (d < 2.0)
        return false;
    }
    else
      return false;
  }

  if (flag && (tmp = document->FindElement("fileheader")))
  {
    LoadFileHeader(tmp);
  }
  else
  {
    LoadFileHeader(null_el);
  }
  
  if (flag && ( tmp = document->FindElement("metrics")))
  {
    LoadMetrics(tmp);
  }
  else
  {
    LoadMetrics(null_el);
  }

  if (flag && ( tmp = document->FindElement("mass_balance")))
  {
    LoadMass(tmp);
  }
  else
  {
    LoadMass(null_el);
  }

  if (flag && ( tmp = document->FindElement("ground_reactions")))
  {
    LoadGR(tmp);
  }
  else
  {
    LoadGR(null_el);
  }

  if (flag && ( tmp = document->FindElement("propulsion")))
  {
    LoadPropulsion(tmp);
  }
  else
  {
    LoadPropulsion(null_el);
  }

  if (flag && ( tmp = document->FindElement("flight_control")))
  {
    LoadFCS(tmp);
  }
  else
  {
    LoadFCS(null_el);
  }

  if (flag && ( tmp = document->FindElement("aerodynamics")))
  {
    LoadAerodynamics(tmp);
  }
  else
  {
    LoadAerodynamics(null_el);
  }

   if (flag && ( tmp = document->FindElement("output")))
  {
    LoadOutput(tmp);
  }
  else
  {
    LoadOutput(null_el);
  }

  tree_ctrl_aerodynamics->Expand(root);
 
  delete null_el;
  delete controls_file_parser;
  return flag;
}

bool AircraftDialog::Save(const wxString &fn)
{
  if (!fn.IsEmpty())
    text_ctrl_info_file->SetValue(fn);

  wxFileOutputStream os(text_ctrl_info_file->GetValue());
  if (!os.Ok())
    return false;
  wxTextOutputStream out(os,wxEOL_UNIX);

  out << wxT("<?xml version=\"1.0\"?>\n");
  out << wxT("<?xml-stylesheet href=\"JSBSim.xsl\" type=\"application/xml\"?>\n");
  out << wxT("<fdm_config name=\"") << text_ctrl_info_name->GetValue() << wxT("\" version=\"") << text_ctrl_info_cfgver->GetValue() << wxT("\" release=\"") << combo_box_info_level->GetValue() << wxT("\">\n");
  
  wxString prefix = wxT("    ");
  
  SaveFileHeader(out, prefix);
  SaveMetrics(out, prefix);
  SaveMass(out, prefix);
  SaveGR(out, prefix);
  SavePropulsion(out, prefix);
  SaveFCS(out, prefix);
  SaveAerodynamics(out, prefix);
  SaveOutput(out, prefix);

  out << wxT("</fdm_config>\n");

  os.Close();
  
  return true;
}

void AircraftDialog::LoadFileHeader(JSBSim::Element * el)
{
  JSBSim::Element * tmp;
  
  if ( tmp = el->FindElement("author"))
  {
    text_ctrl_info_author->SetValue(tmp->GetDataLine());
  }
  else
  {
    text_ctrl_info_author->SetValue(wxT("anonymous"));  
  }
  
  if ( tmp = el->FindElement("filecreationdate"))
  {
    text_ctrl_info_date->SetValue(tmp->GetDataLine());
  }
  else
  {
    text_ctrl_info_date->SetValue(wxDateTime::Now().FormatISODate());
  }

  
  if ( tmp = el->FindElement("version"))
  {
    text_ctrl_info_ver->SetValue(tmp->GetDataLine());
  }
  else
  {
    text_ctrl_info_ver->SetValue(wxT("0.1"));
  }

  
  if ( tmp = el->FindElement("email"))
  {
    text_ctrl_info_email->SetValue(tmp->GetDataLine());
  }
  else
  {
    text_ctrl_info_email->Clear();
  }

  
  text_ctrl_info_desc->Clear();
  if ( tmp = el->FindElement("description"))
  {
    for (int i = 0 ; i < tmp->GetNumDataLines(); ++i)
    {
      wxString str = tmp->GetDataLine(i);
      size_t l = str.Length();
      size_t s=0;
      while ((str[s] == ' ' || str[s]=='\t') && s < l) ++s;
      size_t e = s;
      while (str[e] != ' ' && str[e] != '\t' && e < l) ++e;
      str = str.Mid(s,e);
      if (str.IsEmpty())
	       continue;
      *text_ctrl_info_desc << str;
      if ( tmp->GetNumDataLines() != 1 )
      {
	        *text_ctrl_info_desc << wxT("\n");
      }
    }
  }

  text_ctrl_info_org->Clear();
  if ( tmp = el->FindElement("orgnization"))
  {
    for (int i = 0 ; i < tmp->GetNumDataLines(); ++i)
    {
      wxString str = tmp->GetDataLine(i);
      size_t l = str.Length();
      size_t s=0;
      while ((str[s] == ' ' || str[s]=='\t') && s < l) ++s;
      size_t e = s;
      while (str[e] != ' ' && str[e] != '\t' && e < l) ++e;
      str = str.Mid(s,e);
      if (str.IsEmpty())
	       continue;
      *text_ctrl_info_org << str;
      if ( tmp->GetNumDataLines() != 1 )
      {
	        *text_ctrl_info_org << wxT("\n");
      }
    }
  }
  
  text_ctrl_info_limit->Clear();
  if ( tmp = el->FindElement("limitations"))
  {
    for (int i = 0 ; i < tmp->GetNumDataLines(); ++i)
    {
      wxString str = tmp->GetDataLine(i);
      size_t l = str.Length();
      size_t s=0;
      while ((str[s] == ' ' || str[s]=='\t') && s < l) ++s;
      size_t e = s;
      while (str[e] != ' ' && str[e] != '\t' && e < l) ++e;
      str = str.Mid(s,e);
      if (str.IsEmpty())
	       continue;
      *text_ctrl_info_limit << str;
      if ( tmp->GetNumDataLines() != 1 )
      {
	        *text_ctrl_info_limit << wxT("\n");
      }
    }
  }
  
  text_ctrl_info_notes->Clear();
  if ( tmp = el->FindElement("notes"))
  {
    for (int i = 0 ; i < tmp->GetNumDataLines(); ++i)
    {
      wxString str = tmp->GetDataLine(i);
      size_t l = str.Length();
      size_t s=0;
      while ((str[s] == ' ' || str[s]=='\t') && s < l) ++s;
      size_t e = s;
      while (str[e] != ' ' && str[e] != '\t' && e < l) ++e;
      str = str.Mid(s,e);
      if (str.IsEmpty())
	       continue;
      *text_ctrl_info_notes << str;
      if ( tmp->GetNumDataLines() != 1 )
      {
	        *text_ctrl_info_notes << wxT("\n");
      }
    }
  }
  
  tmp = el->FindElement("reference");
  grid_info_refs->BeginBatch();
  {
    int i;
    for (i=0; i < 10 && tmp; ++i)
    {
      grid_info_refs->SetCellValue(i, 0, tmp->GetAttributeValue("refID"));
      grid_info_refs->SetCellValue(i, 1, tmp->GetAttributeValue("author"));
      grid_info_refs->SetCellValue(i, 2, tmp->GetAttributeValue("title"));
      grid_info_refs->SetCellValue(i, 3, tmp->GetAttributeValue("date"));
      tmp = el->FindNextElement("reference");
    }
    for (; i<10; ++i)
    {
      grid_info_refs->SetCellValue(i, 0, wxEmptyString);
      grid_info_refs->SetCellValue(i, 1, wxEmptyString);
      grid_info_refs->SetCellValue(i, 2, wxEmptyString);
      grid_info_refs->SetCellValue(i, 3, wxEmptyString);    
    }
  }
  grid_info_refs->EndBatch();

}

void AircraftDialog::SaveFileHeader(wxTextOutputStream &out, const wxString & prefix)
{
  wxString pre = wxT("    ");
  out << '\n';
  out << prefix << wxT("<fileheader>\n");
  
  if (! text_ctrl_info_author->GetValue().IsEmpty())
    out << prefix << pre << wxT("<author> ") << text_ctrl_info_author->GetValue() << wxT(" </author>\n");
  
  if (! text_ctrl_info_email->GetValue().IsEmpty())
    out << prefix << pre << wxT("<email> ") << text_ctrl_info_email->GetValue() << wxT(" </email>\n");
  
  if (! text_ctrl_info_org->GetValue().IsEmpty())
  {
    out << prefix << pre << wxT("<orgnization>\n");
    out << text_ctrl_info_org->GetValue();
    out << prefix << pre << wxT("</orgnization>\n");
  }
  
  if (! text_ctrl_info_date->GetValue().IsEmpty())
    out << prefix << pre << wxT("<filecreationdate> ") << text_ctrl_info_date->GetValue() << wxT(" </filecreationdate>\n");
  
  if (! text_ctrl_info_desc->GetValue().IsEmpty())
  {
    out << prefix << pre << wxT("<description>\n");
    out << text_ctrl_info_desc->GetValue();
    out << prefix << pre << wxT("</description>\n");
  }
  
  if (! text_ctrl_info_ver->GetValue().IsEmpty())
    out << prefix << pre << wxT("<version> ") << text_ctrl_info_ver->GetValue() << wxT(" </version>\n");
  
  for (int i=0; i<10; ++i)
  {
    wxString s0, s1, s2, s3;
    s0 = grid_info_refs->GetCellValue(i, 0);
    s1 = grid_info_refs->GetCellValue(i, 1);
    s2 = grid_info_refs->GetCellValue(i, 2);
    s3 = grid_info_refs->GetCellValue(i, 3);
    if (!s0.IsEmpty() || !s1.IsEmpty() || !s2.IsEmpty() || !s3.IsEmpty() )
    {
      out << prefix << pre << wxT("<reference refID=\"") << s0 << wxT("\" author=\"") << s1 << wxT("\" title=\"") << s2 << wxT("\" date=\"") << s3 << wxT("\"/>\n");
    }
  }
  
  if (! text_ctrl_info_limit->GetValue().IsEmpty())
  {
    out << prefix << pre << wxT("<limitations>\n");
    out << text_ctrl_info_limit->GetValue();
    out << prefix << pre << wxT("</limitations>\n");
  }
  
  if (! text_ctrl_info_notes->GetValue().IsEmpty())
  {
    out << prefix << pre << wxT("<notes>\n");
    out << text_ctrl_info_notes->GetValue();
    out << prefix << pre << wxT("</notes>\n");
  }
  
  out << prefix << wxT("</fileheader>\n");
}

void AircraftDialog::LoadMetrics(JSBSim::Element * el)
{
  JSBSim::Element * tmp;
  JSBSim::Element * loc;
  string loc_name;

  if (tmp = el->FindElement("wingarea"))
  {
    text_ctrl_wingarea->SetValue(wxString::Format("%g", tmp->GetDataAsNumber()));
    combo_box_wingarea->SetValue(tmp->GetAttributeValue("unit"));
  }
  else
  {
    text_ctrl_wingarea->SetValue(wxT("0"));
    combo_box_wingarea->SetValue(wxT("M2"));
  }

  if (tmp = el->FindElement("wingspan"))
  {
    text_ctrl_wingspan->SetValue(wxString::Format("%g", tmp->GetDataAsNumber()));
    combo_box_wingspan->SetValue(tmp->GetAttributeValue("unit"));
  }
  else
  {
    text_ctrl_wingspan->SetValue(wxT("0"));
    combo_box_wingspan->SetValue(wxT("M"));
  }

  if (tmp = el->FindElement("chord"))
  {
    text_ctrl_chord->SetValue(wxString::Format("%g", tmp->GetDataAsNumber()));
    combo_box_chord->SetValue(tmp->GetAttributeValue("unit"));
  }
  else
  {
    text_ctrl_chord->SetValue(wxT("0"));
    combo_box_chord->SetValue(wxT("M"));  
  }

  if (tmp = el->FindElement("wing_incidence"))
  {
    text_ctrl_wincidence->SetValue(wxString::Format("%g", tmp->GetDataAsNumber()));
    combo_box_wincidence->SetValue(tmp->GetAttributeValue("unit"));
  }
  else
  {
    text_ctrl_wincidence->SetValue(wxT("0"));
    combo_box_wincidence->SetValue(wxT("DEG"));
  }

  if (tmp = el->FindElement("htailarea"))
  {
    text_ctrl_htailarea->SetValue(wxString::Format("%g", tmp->GetDataAsNumber()));
    combo_box_htailarea->SetValue(tmp->GetAttributeValue("unit"));
  }
  else
  {
    text_ctrl_htailarea->SetValue(wxT("0"));
    combo_box_htailarea->SetValue(wxT("M2"));
  }

  if (tmp = el->FindElement("htailarm"))
  {
    text_ctrl_htailarm->SetValue(wxString::Format("%g", tmp->GetDataAsNumber()));
    combo_box_htailarm->SetValue(tmp->GetAttributeValue("unit"));
  }
  else
  {
    text_ctrl_htailarm->SetValue(wxT("0"));
    combo_box_htailarm->SetValue(wxT("M"));
  }

  if (tmp = el->FindElement("vtailarea"))
  {
    text_ctrl_vtailarea->SetValue(wxString::Format("%g", tmp->GetDataAsNumber()));
    combo_box_vtailarea->SetValue(tmp->GetAttributeValue("unit"));
  }
  else
  {
    text_ctrl_vtailarea->SetValue(wxT("0"));
    combo_box_vtailarea->SetValue(wxT("M2"));
  }

  if (tmp = el->FindElement("vtailarm"))
  {
    text_ctrl_vtailarm->SetValue(wxString::Format("%g", tmp->GetDataAsNumber()));
    combo_box_vtailarm->SetValue(tmp->GetAttributeValue("unit"));
  }
  else
  {
    text_ctrl_vtailarm->SetValue(wxT("0"));
    combo_box_vtailarm->SetValue(wxT("M"));
  }

  // Find all LOCATION that descend from this METRICS branch of the
  // config file. This would be CG location, eyepoint, etc.

  text_ctrl_arp_x->SetValue(wxT("0"));
  text_ctrl_arp_y->SetValue(wxT("0"));
  text_ctrl_arp_z->SetValue(wxT("0"));
  combo_box_arp_unit->SetValue(wxT("M"));
  text_ctrl_ep_x->SetValue(wxT("0"));
  text_ctrl_ep_y->SetValue(wxT("0"));
  text_ctrl_ep_z->SetValue(wxT("0"));
  combo_box_ep_unit->SetValue(wxT("M"));
  text_ctrl_vrp_x->SetValue(wxT("0"));
  text_ctrl_vrp_y->SetValue(wxT("0"));
  text_ctrl_vrp_z->SetValue(wxT("0"));
  combo_box_vrp_unit->SetValue(wxT("M"));
  
  loc = el->FindElement("location");
  while (loc) {
    loc_name = loc->GetAttributeValue("name");

    if (loc_name == "AERORP")
    {
      combo_box_arp_unit->SetValue(loc->GetAttributeValue("unit"));
      text_ctrl_arp_x->SetValue(wxString::Format("%g", loc->FindElementValueAsNumber("x")));
      text_ctrl_arp_y->SetValue(wxString::Format("%g", loc->FindElementValueAsNumber("y")));
      text_ctrl_arp_z->SetValue(wxString::Format("%g", loc->FindElementValueAsNumber("z")));
    }
    else if (loc_name == "EYEPOINT")
    {
      combo_box_ep_unit->SetValue(loc->GetAttributeValue("unit"));
      text_ctrl_ep_x->SetValue(wxString::Format("%g", loc->FindElementValueAsNumber("x")));
      text_ctrl_ep_y->SetValue(wxString::Format("%g", loc->FindElementValueAsNumber("y")));
      text_ctrl_ep_z->SetValue(wxString::Format("%g", loc->FindElementValueAsNumber("z")));
    }
    else if (loc_name == "VRP")
    {
      combo_box_vrp_unit->SetValue(loc->GetAttributeValue("unit"));
      text_ctrl_vrp_x->SetValue(wxString::Format("%g", loc->FindElementValueAsNumber("x")));
      text_ctrl_vrp_y->SetValue(wxString::Format("%g", loc->FindElementValueAsNumber("y")));
      text_ctrl_vrp_z->SetValue(wxString::Format("%g", loc->FindElementValueAsNumber("z")));
    }

    loc = el->FindNextElement("location");
  }

}

void AircraftDialog::SaveMetrics(wxTextOutputStream &out, const wxString & prefix)
{
  wxString pre = wxT("    ");
  out << '\n';
  out << prefix << wxT("<metrics>\n");
  out << prefix << pre << wxT("<wingarea unit=\"") << combo_box_wingarea->GetValue() << wxT("\"> ") << text_ctrl_wingarea->GetValue() << wxT(" </wingarea>\n");
  out << prefix << pre << wxT("<wingspan unit=\"") << combo_box_wingspan->GetValue() << wxT("\"> ") << text_ctrl_wingspan->GetValue() << wxT(" </wingspan>\n");
  out << prefix << pre << wxT("<chord unit=\"") << combo_box_chord->GetValue() << wxT("\"> ") << text_ctrl_chord->GetValue() << wxT(" </chord>\n");
  out << prefix << pre << wxT("<wing_incidence unit=\"") << combo_box_wincidence->GetValue() << wxT("\"> ") << text_ctrl_wincidence->GetValue() << wxT(" </wing_incidence>\n");
  out << prefix << pre << wxT("<htailarea unit=\"") << combo_box_htailarea->GetValue() << wxT("\"> ") << text_ctrl_htailarea->GetValue() << wxT(" </htailarea>\n");
  out << prefix << pre << wxT("<htailarm unit=\"") << combo_box_htailarm->GetValue() << wxT("\"> ") << text_ctrl_htailarm->GetValue() << wxT(" </htailarm>\n");
  out << prefix << pre << wxT("<vtailarea unit=\"") << combo_box_vtailarea->GetValue() << wxT("\"> ") << text_ctrl_vtailarea->GetValue() << wxT(" </vtailarea>\n");
  out << prefix << pre << wxT("<vtailarm unit=\"") << combo_box_vtailarm->GetValue() << wxT("\"> ") << text_ctrl_vtailarm->GetValue() << wxT(" </vtailarm>\n");

  out << prefix << pre << wxT("<location name=\"AERORP\" unit=\"") << combo_box_arp_unit->GetValue() << wxT("\">\n");
  out << prefix << pre << pre << wxT("<x> ") << text_ctrl_arp_x->GetValue() << wxT(" </x>\n");
  out << prefix << pre << pre << wxT("<y> ") << text_ctrl_arp_y->GetValue() << wxT(" </y>\n");
  out << prefix << pre << pre << wxT("<z> ") << text_ctrl_arp_z->GetValue() << wxT(" </z>\n");
  out << prefix << pre << wxT("</location>\n");

  out << prefix << pre << wxT("<location name=\"EYEPOINT\" unit=\"") <<  combo_box_ep_unit->GetValue() << wxT("\">\n");
  out << prefix << pre << pre << wxT("<x> ") << text_ctrl_ep_x->GetValue() << wxT(" </x>\n");
  out << prefix << pre << pre << wxT("<y> ") << text_ctrl_ep_y->GetValue() << wxT(" </y>\n");
  out << prefix << pre << pre << wxT("<z> ") << text_ctrl_ep_z->GetValue() << wxT(" </z>\n");
  out << prefix << pre << wxT("</location>\n");

  out << prefix << pre << wxT("<location name=\"VRP\" unit=\"") <<  combo_box_vrp_unit->GetValue() << wxT("\">\n");
  out << prefix << pre << pre << wxT("<x> ") << text_ctrl_vrp_x->GetValue() << wxT(" </x>\n");
  out << prefix << pre << pre << wxT("<y> ") << text_ctrl_vrp_y->GetValue() << wxT(" </y>\n");
  out << prefix << pre << pre << wxT("<z> ") << text_ctrl_vrp_z->GetValue() << wxT(" </z>\n");
  out << prefix << pre << wxT("</location>\n");
  
  out << prefix << wxT("</metrics>\n");

}


void AircraftDialog::LoadMass(JSBSim::Element * el)
{
  JSBSim::Element * temp_element;

  if (temp_element = el->FindElement("ixx")) {
    text_ctrl_ixx->SetValue(wxString::Format("%g", temp_element->GetDataAsNumber()));
    combo_box_ixx->SetValue(temp_element->GetAttributeValue("unit"));
  }
  else {
    text_ctrl_ixx->SetValue(wxT("0"));
    combo_box_ixx->SetValue(wxT("KG*M2"));
  }

  if (temp_element = el->FindElement("iyy")) {
    text_ctrl_iyy->SetValue(wxString::Format("%g", temp_element->GetDataAsNumber()));
    combo_box_iyy->SetValue(temp_element->GetAttributeValue("unit"));
  }
  else {
    text_ctrl_iyy->SetValue(wxT("0"));
    combo_box_iyy->SetValue(wxT("KG*M2"));
  }

  if (temp_element = el->FindElement("izz")) {
    text_ctrl_izz->SetValue(wxString::Format("%g", temp_element->GetDataAsNumber()));
    combo_box_izz->SetValue(temp_element->GetAttributeValue("unit"));
  }
  else {
    text_ctrl_izz->SetValue(wxT("0"));
    combo_box_izz->SetValue(wxT("KG*M2"));
  }

  if (temp_element = el->FindElement("ixz")) {
    text_ctrl_ixz->SetValue(wxString::Format("%g", temp_element->GetDataAsNumber()));
    combo_box_ixz->SetValue(temp_element->GetAttributeValue("unit"));
  }
  else {
    text_ctrl_ixz->SetValue(wxT("0"));
    combo_box_ixz->SetValue(wxT("KG*M2"));
  }

  if (temp_element = el->FindElement("iyz")) {
    text_ctrl_iyz->SetValue(wxString::Format("%g", temp_element->GetDataAsNumber()));
    combo_box_iyz->SetValue(temp_element->GetAttributeValue("unit"));
  }
  else {
    text_ctrl_iyz->SetValue(wxT("0"));
    combo_box_iyz->SetValue(wxT("KG*M2"));
  }

  if (temp_element = el->FindElement("ixy")) {
    text_ctrl_ixy->SetValue(wxString::Format("%g", temp_element->GetDataAsNumber()));
    combo_box_ixy->SetValue(temp_element->GetAttributeValue("unit"));
  }
  else {
    text_ctrl_ixy->SetValue(wxT("0"));
    combo_box_ixy->SetValue(wxT("KG*M2"));
  }


  if (temp_element = el->FindElement("emptywt")) {
    text_ctrl_mass->SetValue(wxString::Format("%g", temp_element->GetDataAsNumber()));
    combo_box_mass_unit->SetValue(temp_element->GetAttributeValue("unit"));
  }
  else {
    text_ctrl_mass->SetValue(wxT("0"));
    combo_box_mass_unit->SetValue(wxT("KG"));
  }

  text_ctrl_mass_x->SetValue(wxT("0"));
  text_ctrl_mass_y->SetValue(wxT("0"));
  text_ctrl_mass_z->SetValue(wxT("0"));
  combo_box_mass_locunit->SetValue(wxT("M"));
  JSBSim::Element * el_loc;
  el_loc = el->FindElement("location");
  while (el_loc) {
    if (el_loc->GetAttributeValue("name")=="CG")
    {
      text_ctrl_mass_x->SetValue(wxString::Format("%g", el_loc->FindElementValueAsNumber("x")));
      text_ctrl_mass_y->SetValue(wxString::Format("%g", el_loc->FindElementValueAsNumber("y")));
      text_ctrl_mass_z->SetValue(wxString::Format("%g", el_loc->FindElementValueAsNumber("z")));
      combo_box_mass_locunit->SetValue(el_loc->GetAttributeValue("unit"));
    }
    el_loc = el->FindNextElement("location");
  }

  list_box_pm->Clear();
  JSBSim::Element * el_pm;
  el_pm = el->FindElement("pointmass");
  while (el_pm) {
    ClientData_pm * tmp = new ClientData_pm;
    tmp->Load(el_pm);
    list_box_pm->Append(tmp->GetText(), tmp);

    el_pm = el->FindNextElement("pointmass");
  }

}

void AircraftDialog::SaveMass(wxTextOutputStream &out, const wxString & prefix)
{
  out << '\n';
  out << prefix << wxT("<mass_balance>\n");

  wxString pre = prefix + wxT("    ");

  out << pre << wxT("<ixx unit=\"") << combo_box_ixx->GetValue() << wxT("\">") << text_ctrl_ixx->GetValue() << wxT("</ixx>\n");
  out << pre << wxT("<iyy unit=\"") << combo_box_iyy->GetValue() << wxT("\">") << text_ctrl_iyy->GetValue() << wxT("</iyy>\n");
  out << pre << wxT("<izz unit=\"") << combo_box_izz->GetValue() << wxT("\">") << text_ctrl_izz->GetValue() << wxT("</izz>\n");
  out << pre << wxT("<ixz unit=\"") << combo_box_ixz->GetValue() << wxT("\">") << text_ctrl_ixz->GetValue() << wxT("</ixz>\n");
  out << pre << wxT("<iyz unit=\"") << combo_box_iyz->GetValue() << wxT("\">") << text_ctrl_iyz->GetValue() << wxT("</iyz>\n");
  out << pre << wxT("<ixy unit=\"") << combo_box_ixy->GetValue() << wxT("\">") << text_ctrl_ixy->GetValue() << wxT("</ixy>\n");
  
  out << pre << wxT("<emptywt unit=\"") << combo_box_mass_unit->GetValue() << wxT("\">") << text_ctrl_mass->GetValue() << wxT("</emptywt>\n");
  out << pre << wxT("<location name=\"CG\" unit=\"") << combo_box_mass_locunit->GetValue() << wxT("\">\n");
  out << pre << wxT("    <x>") << text_ctrl_mass_x->GetValue() << wxT("</x>\n");
  out << pre << wxT("    <y>") << text_ctrl_mass_y->GetValue() << wxT("</y>\n");
  out << pre << wxT("    <z>") << text_ctrl_mass_z->GetValue() << wxT("</z>\n");
  out << pre << wxT("</location>\n");

  for (int i=0; i < list_box_pm->GetCount(); ++i )
  {
    ClientData_pm * tmp = dynamic_cast<ClientData_pm *>(list_box_pm->GetClientObject(i));
    if (tmp)
      tmp->Save(out, pre);
  }
  
  out << prefix << wxT("</mass_balance>\n");
}

void AircraftDialog::LoadGR(JSBSim::Element * el)
{
  list_ctrl_gr->Clear();
  JSBSim::Element * el_pm;
  el_pm = el->FindElement("contact");
  while (el_pm) {
    ClientData_LGear * tmp = new ClientData_LGear;
    tmp->Load(el_pm);
    list_ctrl_gr->Append(tmp->GetText(), tmp);

    el_pm = el->FindNextElement("contact");
  }
}

void AircraftDialog::SaveGR(wxTextOutputStream &out, const wxString & prefix)
{
  out << '\n';
  out << prefix << wxT("<ground_reactions>\n");

  wxString pre = prefix + wxT("    ");

  for (int i=0; i < list_ctrl_gr->GetCount(); ++i )
  {
    ClientData_LGear * tmp = dynamic_cast<ClientData_LGear *>(list_ctrl_gr->GetClientObject(i));
    if (tmp)
      tmp->Save(out, pre);
  }
  
  out << prefix << wxT("</ground_reactions>\n");

}

void AircraftDialog::LoadPropulsion(JSBSim::Element * el)
{
  JSBSim::Element * tmp;
  long no;

  list_ctrl_sub_engines->DeleteAllItems();
  engines.clear(); 
  tmp = el->FindElement("engine");
  no = 0;
  while (tmp)
  {
    ClientData_engine engine;
    engine.Load(tmp);
    engines.push_back(engine);
    int image;
    wxListItem item;
    item.SetMask(wxLIST_MASK_IMAGE|wxLIST_MASK_DATA|wxLIST_MASK_TEXT);
    {
      long tmp = list_ctrl_avail_engines->FindItem(-1, engine.GetEngineName());
      if (tmp >=0 )
      {
        item.m_itemId = tmp;
        item.m_col = 0;
        list_ctrl_avail_engines->GetItem(item);
        image = item.m_image;
      }
      else
      {
        image = -1;
      }
    }
    list_ctrl_sub_engines->InsertItem(no, engine.GetEngineName(), image);
    list_ctrl_sub_engines->SetItemData(no, engines.size()-1);
    {
      long tmp = list_ctrl_avail_thruster->FindItem(-1, engine.GetThrusterName());
      if (tmp >=0 )
      {
        item.m_itemId = tmp;
        item.m_col = 0;
        list_ctrl_avail_thruster->GetItem(item);
        image = item.m_image;
      }
      else
      {
        image = -1;
      }
    }
    list_ctrl_sub_engines->SetItem(no++, 1, engine.GetThrusterName(), image);
    tmp = el->FindNextElement("engine");
  }
  list_ctrl_sub_engines->SetColumnWidth( 0, wxLIST_AUTOSIZE );
  list_ctrl_sub_engines->SetColumnWidth( 1, wxLIST_AUTOSIZE );

  list_ctrl_tanks->DeleteAllItems();
  tanks.clear();
  tmp = el->FindElement("tank");
  no = 0;
  while (tmp)
  {
    ClientData_tank tank;
    tank.Load(tmp);
    tanks.push_back(tank);
    list_ctrl_tanks->InsertItem(no, tank.GetText(), 35);
    list_ctrl_tanks->SetItemData(no++, tanks.size()-1);
    tmp = el->FindNextElement("tank");
  }
  list_ctrl_tanks->SetColumnWidth( 0, wxLIST_AUTOSIZE );
}

void AircraftDialog::SavePropulsion(wxTextOutputStream &out, const wxString & prefix)
{
    out << endl;
    out << prefix << wxT("<propulsion>\n");

    wxString pre = prefix + wxT("    ");
    long item;
  
    item = -1;
    for ( ;; )
    {
        item = list_ctrl_sub_engines->GetNextItem(item, wxLIST_NEXT_ALL);
        if ( item == -1 )
            break;
        long tmp = list_ctrl_sub_engines->GetItemData(item);
        engines[tmp].Save(out, pre);
    }

    item = -1;
    for ( ;; )
    {
        item = list_ctrl_tanks->GetNextItem(item, wxLIST_NEXT_ALL);
        if ( item == -1 )
            break;
        long tmp = list_ctrl_tanks->GetItemData(item);
        tanks[tmp].Save(out, pre);
    }

    out << prefix << wxT("</propulsion>\n");
}

void AircraftDialog::LoadFCS(JSBSim::Element * el)
{
  notebook_ac_pane_fcs->ClearAll();
  fcsfile = el->GetAttributeValue("file");
  if ( !fcsfile.IsEmpty() )
  {
    wxString file = text_ctrl_info_file->GetValue();
    file = file.BeforeLast(wxGetApp().Delimited[0]) + wxGetApp().Delimited + fcsfile + wxT(".xml");
    notebook_ac_pane_fcs->ImportXML(file);
  }
  else
  {
    notebook_ac_pane_fcs->Import(el);
  }
}

void AircraftDialog::SaveFCS(wxTextOutputStream &out, const wxString & prefix)
{
  if (!fcsfile.IsEmpty())
  {
    wxString file = text_ctrl_info_file->GetValue();
    file = file.BeforeLast(wxGetApp().Delimited[0]) + wxGetApp().Delimited + fcsfile + wxT(".xml");
    notebook_ac_pane_fcs->ExportXML(file);
    out << '\n';
    out << prefix << wxT("<flight_control file=\"") << fcsfile << wxT("\"/>\n");
  }
  else
  {
    notebook_ac_pane_fcs->Export(out, prefix);  
  }
}

void AircraftDialog::LoadAerodynamics(JSBSim::Element * el)
{
  aerodynamics_data->Load(el);
}

void AircraftDialog::SaveAerodynamics(wxTextOutputStream &out, const wxString & prefix)
{
  out << '\n';
  aerodynamics_data->Save(out, prefix);
}

void AircraftDialog::LoadOutput(JSBSim::Element * el)
{
  JSBSim::FGXMLParse output_file_parser;
  JSBSim::Element *document, *property_element;

  wxString fname = el->GetAttributeValue("file");
  if (!fname.IsEmpty()) {
    wxString filename = text_ctrl_info_file->GetValue();
    wxString path=wxEmptyString;
    path = filename.BeforeLast(wxGetApp().Delimited[0]) + wxGetApp().Delimited;      
    wxString output_file_name = path + fname + wxT(".xml");

    std::ifstream output_file;
    output_file.open(output_file_name.c_str());
    try
    {
      readXML(output_file, output_file_parser);
    }
    catch(...)
    {
      ::wxMessageBox(wxT("Fail to parse file ")+output_file_name, wxT("Error"), wxOK | wxICON_ERROR, this);
      return;
    }
    document = output_file_parser.GetDocument();
  } else {
    document = el;
  }
  
  wxString   name = wxT("JSBout.csv");
  wxString   type = wxT("CSV");
  name = document->GetAttributeValue("name");
  type = document->GetAttributeValue("type");
  if (type == wxT("socket"))
  {
     wxMessageBox(_("socket type is not surported right now. I will use CSV instead."), wxT("Info"), wxOK | wxICON_INFORMATION, NULL);
     type = wxT("CSV");
     name = name.BeforeLast('.') + wxT(".csv");
  }
  if (name.IsEmpty())
  {
    name = wxT("JSBout.csv");
    type = wxT("CSV");
  }
  text_ctrl_output_name->SetValue(name);
  combo_box_output_type->SetValue(type);

  if (!document->GetAttributeValue("rate").empty()) {
    text_ctrl_output_rate->SetValue(wxString::Format("%d", (int)document->GetAttributeValueAsNumber("rate")));
  } else {
    text_ctrl_output_rate->SetValue(wxT("100"));
  }

  if (document->FindElementValue("simulation") == string("ON"))
    checkbox_output_simu->SetValue(true);
  else
    checkbox_output_simu->SetValue(false);
  if (document->FindElementValue("aerosurfaces") == string("ON"))
    checkbox_output_sur->SetValue(true);
  else
    checkbox_output_sur->SetValue(false);
  if (document->FindElementValue("rates") == string("ON"))
    checkbox_output_rates->SetValue(true);
  else
    checkbox_output_rates->SetValue(false);
  if (document->FindElementValue("velocities") == string("ON"))
    checkbox_output_vel->SetValue(true);
  else
    checkbox_output_vel->SetValue(false);
  if (document->FindElementValue("forces") == string("ON"))
    checkbox_output_forc->SetValue(true);
  else
    checkbox_output_forc->SetValue(false);
  if (document->FindElementValue("moments") == string("ON"))
    checkbox_output_moments->SetValue(true);
  else
    checkbox_output_moments->SetValue(false);
  if (document->FindElementValue("atmosphere") == string("ON"))
    checkbox_output_atmo->SetValue(true);
  else
    checkbox_output_atmo->SetValue(false);
  if (document->FindElementValue("massprops") == string("ON"))
    checkbox_output_mass->SetValue(true);
  else
    checkbox_output_mass->SetValue(false);
  if (document->FindElementValue("position") == string("ON"))
    checkbox_output_pos->SetValue(true);
  else
    checkbox_output_pos->SetValue(false);
  if (document->FindElementValue("coefficients") == string("ON"))
    checkbox_output_coeff->SetValue(true);
  else
    checkbox_output_coeff->SetValue(false);
  if (document->FindElementValue("ground_reactions") == string("ON"))
    checkbox_output_ground->SetValue(true);
  else
    checkbox_output_ground->SetValue(false);
  if (document->FindElementValue("fcs") == string("ON"))
    checkbox_output_fcs->SetValue(true);
  else
    checkbox_output_fcs->SetValue(false);
  if (document->FindElementValue("propulsion") == string("ON"))
    checkbox_output_propulsion->SetValue(true);
  else
    checkbox_output_propulsion->SetValue(false);

  list_box_output_adds->Clear();
  property_element = document->FindElement("property");
  while (property_element) {
    list_box_output_adds->Append(property_element->GetDataLine());
    property_element = document->FindNextElement("property");
  }
}

void AircraftDialog::SaveOutput(wxTextOutputStream &out, const wxString & prefix)
{
  out << endl;
  out << prefix << wxT("<output name=\"") << text_ctrl_output_name->GetValue() << wxT("\" type=\"") << combo_box_output_type->GetValue() << wxT("\" rate=\"") << text_ctrl_output_rate->GetValue() << wxT("\">\n");

  wxString pre = prefix + wxT("    ");

  out << pre << wxT("<simulation>");
  if (checkbox_output_simu->GetValue())
    out << wxT(" ON ");
  else
    out << wxT(" OFF ");
  out << wxT("</simulation>\n");

  out << pre << wxT("<atmosphere>");
  if (checkbox_output_atmo->GetValue())
    out << wxT(" ON ");
  else
    out << wxT(" OFF ");
  out << wxT("</atmosphere>\n");

  out << pre << wxT("<massprops>");
  if (checkbox_output_mass->GetValue())
    out << wxT(" ON ");
  else
    out << wxT(" OFF ");
  out << wxT("</massprops>\n");

  out << pre << wxT("<aerosurfaces>");
  if (checkbox_output_sur->GetValue())
    out << wxT(" ON ");
  else
    out << wxT(" OFF ");
  out << wxT("</aerosurfaces>\n");

  out << pre << wxT("<rates>");
  if (checkbox_output_rates->GetValue())
    out << wxT(" ON ");
  else
    out << wxT(" OFF ");
  out << wxT("</rates>\n");
    
  out << pre << wxT("<velocities>");
  if (checkbox_output_vel->GetValue())
    out << wxT(" ON ");
  else
    out << wxT(" OFF ");
  out << wxT("</velocities>\n");
  
  out << pre << wxT("<forces>");
  if (checkbox_output_forc->GetValue())
    out << wxT(" ON ");
  else
    out << wxT(" OFF ");
  out << wxT("</forces>\n");

  out << pre << wxT("<moments>");
  if (checkbox_output_moments->GetValue())
    out << wxT(" ON ");
  else
    out << wxT(" OFF ");
  out << wxT("</moments>\n");

  out << pre << wxT("<position>");
  if (checkbox_output_pos->GetValue())
    out << wxT(" ON ");
  else
    out << wxT(" OFF ");
  out << wxT("</position>\n");

  out << pre << wxT("<coefficients>");
  if (checkbox_output_coeff->GetValue())
    out << wxT(" ON ");
  else
    out << wxT(" OFF ");
  out << wxT("</coefficients>\n");

  out << pre << wxT("<ground_reactions>");
  if (checkbox_output_ground->GetValue())
    out << wxT(" ON ");
  else
    out << wxT(" OFF ");
  out << wxT("</ground_reactions>\n");

  out << pre << wxT("<fcs>");
  if (checkbox_output_fcs->GetValue())
    out << wxT(" ON ");
  else
    out << wxT(" OFF ");
  out << wxT("</fcs>\n");

  out << pre << wxT("<propulsion>");
  if (checkbox_output_propulsion->GetValue())
    out << wxT(" ON ");
  else
    out << wxT(" OFF ");
  out << wxT("</propulsion>\n");

  for (size_t i = 0; i < list_box_output_adds->GetCount(); ++i)
  {
    out << pre << wxT("<property>") << list_box_output_adds->GetString(i) << wxT("</property>\n");
  }

  out << prefix << wxT("</output>\n");
}


